Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I've got a localscript that only works on studio mode. Any ideas why?

Asked by 7 years ago
Edited by Pyrondon 7 years ago
p = game.Players.LocalPlayer
repeat wait() until p:FindFirstChild("Backpack")
function Click()
    wait(2)
repeat wait() until p:FindFirstChild("Backpack")
game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
end

script.Parent.MouseButton1Click:connect(Click)
--// Put your code in a code block. Blue button in code editor. Code in between, all that, yeah.

This is in a localscript inside of a textbutton. When the weapons are given to the player, over half of them don't work, and it only happens to players are given the weapons by this script.

1
You need to learn how to use WaitForChild. User#11440 120 — 7y

1 answer

Log in to vote
0
Answered by
Valatos 166
7 years ago
Edited 7 years ago
p = game.Players.LocalPlayer
p:WaitForChild("Backpack") -- Waiting for the backpack before we continue our script
function Click()
game.ReplicatedStorage:GetChildren() [math.random(1,        #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
game.ReplicatedStorage:GetChildren() [math.random(1,               #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
game.ReplicatedStorage:GetChildren() [math.random(1,                    
#game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
end
script.Parent.MouseButton1Click:connect(Click)

The only thing i edited was the WaitForChild function

Ad

Answer this question