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!

1 comment
i forgot to mention that you also have to reach for character and the player running the code, which is also a arg of MouseButton1Click, If it doesnt work, try gui.Parent.Parent.