DropButton is in a frame clled DropFrame in a screengui called Main
- User
DropButton is in a frame clled DropFrame in a screengui called Main
Assistant
Here's the updated server-side script that correctly references the
DropButtonlocated inside aScreenGuicalledMain, within aFramecalledDropFrame. This script ensures the button is found in the correct GUI hierarchy and spawns a random model from thePetsfolder when clicked.
✅ Updated Server Script (Place in
ServerScriptService)local ReplicatedStorage = game:GetService("ReplicatedStorage") local Workspace = game:GetService("Workspace") local Players = game:GetService("Players") -- Function to spawn a random pet model at the Spawn part local function spawnRandomPet() local spawnPart = Workspace:FindFirstChild("Spawn") if not spawnPart then warn("Spawn part not found in Workspace!") return end local petsFolder = ReplicatedStorage:FindFirstChild("Pets") if not petsFolder then warn("Pets folder not found in ReplicatedStorage!") return end local petModels = petsFolder:GetChildren() if #petModels == 0 then warn("No models found in Pets folder!") return end local randomIndex = math.random(1, #petModels) local randomPet = petModels[randomIndex]:Clone() -- Ensure the model has a PrimaryPart if not randomPet.PrimaryPart then for _, part in ipairs(randomPet:GetChildren()) do if part:IsA("BasePart") then randomPet.PrimaryPart = part break end end if not randomPet.PrimaryPart then warn("Random pet model has no PrimaryPart and no BasePart to assign!") return end end randomPet:SetPrimaryPartCFrame(spawnPart.CFrame) randomPet.Parent = Workspace end -- Listen for players joining Players.PlayerAdded:Connect(function(player) -- Wait for the PlayerGui to be ready local playerGui = player:WaitForChild("PlayerGui", 10) if not playerGui then warn("PlayerGui not found for player: " .. player.Name) return end -- Find the Main ScreenGui inside PlayerGui local mainScreen = playerGui:WaitForChild("Main", 10) if not mainScreen then warn("Main ScreenGui not found for player: " .. player.Name) return end -- Find the DropFrame inside Main local dropFrame = mainScreen:WaitForChild("DropFrame", 10) if not dropFrame then warn("DropFrame not found in Main ScreenGui for player: " .. player.Name) return end -- Find the DropButton inside DropFrame local dropButton = dropFrame:WaitForChild("DropButton", 10) if not dropButton or not dropButton:IsA("TextButton") then warn("DropButton not found or not a TextButton in DropFrame for player: " .. player.Name) return end -- Connect the button click event dropButton.Activated:Connect(function() spawnRandomPet() end) end)
📌 Key Notes:
-
GUI Hierarchy Assumed:
PlayerGui→Main(ScreenGui) →DropFrame(Frame) →DropButton(TextButton)- If your structure is different, adjust the path accordingly (e.g., if the
MainScreenGui is in a different location).
-
Security:
- This script runs on the server, so it’s secure and prevents cheating.
- The
DropButtonis part of the player’s GUI, not the character, so it doesn’t interfere with the player’s avatar.
-
Error Handling:
- The script includes timeouts (
WaitForChild(10)) to avoid infinite waits if the GUI elements are missing. - Warnings are logged if any part of the GUI path is missing.
- The script includes timeouts (
-
Pet Model Requirements:
- Models in the
Petsfolder must have aPrimaryPartset, or at least oneBasePartto act as the primary part.
- Models in the
🛠️ Example GUI Structure:
Ensure your game has this structure:
PlayerGui ├── Main (ScreenGui) │ └── DropFrame (Frame) │ └── DropButton (TextButton)If your
MainScreenGui is in a different location (e.g.,StarterGui), update the script accordingly.Let me know if you'd like a client-side version or need help setting up the GUI!
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.