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 8 years ago
Edited by Pyrondon 8 years ago
01p = game.Players.LocalPlayer
02repeat wait() until p:FindFirstChild("Backpack")
03function Click()
04    wait(2)
05repeat wait() until p:FindFirstChild("Backpack")
06game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
07game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
08game.ReplicatedStorage:GetChildren() [math.random(1, #game.ReplicatedStorage:GetChildren())]:clone().Parent = p.Backpack
09end
10 
11script.Parent.MouseButton1Click:connect(Click)
12--// 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 — 8y

1 answer

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

The only thing i edited was the WaitForChild function

Ad

Answer this question