Hello!
I wanted to make a sandbox, where players can spawn different models. I did a code:
local btn = script.Parent local frame = btn.Parent local gui = frame.Parent local txtbx = frame:FindFirstChild("TextBox") local finish = txtbx.Text local zero = 0 btn.MouseButton1Click:Connect(function() -- button listens for clicks ---------------------------------------------------------------------------------- local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) -- Getting humanoid's root part local humrootpart = character:WaitForChild("HumanoidRootPart") local pos = humrootpart.Position ---------------------------------------------------------------------------------- local folder = Instance.new('Folder') -- creating new folder folder.Name = "Parts" folder.Parent = workspace if finish > 0 and finish < 100 then repeat zero = zero + 1 local part = Instance.new('part') -- creating new part part.Transparency = 0 part.Anchored = false part.Shape = 'Block' part.Position = pos + Vector3.new(7, 10, 0) part.Parent = folder part.Size = Vector3.new(3, 3, 3) part.BrickColor = BrickColor.Random() wait(1) -- delay between repeats print("blocks count: ", zero) until zero == finish zero = 0 print("zero is 0") else -- if value isn't between 1 and 100 txtbx.Text = "Please enter values between 1 and 100 only" end end) end) end)
So when player clicks on button, it creates a folder and the number of blocks that the player entered will spawn. But some reason, it doesn't work at all. I don't understand why. I placed almost the same script to a part, so when player touches the part, script will run. And it worked! But when i tried the same thing with gui, it doesn't run. Help!
I dont think GUI's are really supposed to be for things that your talking about. as far as I can see, your script is right. thats why i am saying that. please message me on roblox if you have anymore questions.
Everytime you press that button, it makes a connection across the entire game that when a player's character spawns, it creates that amount of blocks.
Which is, well, non functional.
the solution? remove 4 lines.
If ran from the server, it will be perfectly functional.
local btn = script.Parent local frame = btn.Parent local gui = frame.Parent local txtbx = frame:FindFirstChild("TextBox") local finish = txtbx.Text local zero = 0 btn.MouseButton1Click:Connect(function() -- button listens for clicks ---------------------------------------------------------------------------------- local humrootpart = character:WaitForChild("HumanoidRootPart") local pos = humrootpart.Position ---------------------------------------------------------------------------------- local folder = Instance.new('Folder') -- creating new folder folder.Name = "Parts" folder.Parent = workspace if finish > 0 and finish < 100 then repeat zero = zero + 1 local part = Instance.new('part') -- creating new part part.Transparency = 0 part.Anchored = false part.Shape = 'Block' part.Position = pos + Vector3.new(7, 10, 0) part.Parent = folder part.Size = Vector3.new(3, 3, 3) part.BrickColor = BrickColor.Random() wait(1) -- delay between repeats print("blocks count: ", zero) until zero == finish zero = 0 print("zero is 0") else -- if value isn't between 1 and 100 txtbx.Text = "Please enter values between 1 and 100 only" end end)