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

Why does this work on studio only?

Asked by 8 years ago

I made this script, and it only runs in studio, i have asked this question several times and i got nothing much but this line of code that someone told me to put on the top of every local script.

--This is the code i got told to put on top of a local script
repeat wait() until game.Players.LocalPlayer.Character

So i did put the code on top of the local script and it didnt work, but only on studio.

repeat wait() until game.Players.LocalPlayer.Character
Player = game.Players.LocalPlayer
Cube = script.Parent
local Workspace = game.Workspace
mouse = Player:GetMouse()


local SwordFold = game.ServerStorage.Sword


local Sword = {
"Sword"

}


function Click()
while true do
for i,v in pairs(SwordFold:GetChildren())do
if v.Name == Sword[math.random(1, #Sword)] then
wait()
v.Enabled = true
local Gear = v:Clone()
Gear.Parent = Player.Backpack
Sound:Play()
print(Player.Name,"Got", v.Name.."!")
wait()
script.Parent:Destroy()

end
end
end







end




Cube.Activated:connect(Click)
Cube.Equipped:connect(onEquipped)

1 answer

Log in to vote
1
Answered by 8 years ago

ServerStorage doesn't exist in servers, it is a place where you can store stuff while you work in studio. Put the sword in ReplicatedStorage and

Try this:

repeat wait() until game.Players.LocalPlayer.Character
Player = game.Players.LocalPlayer
Cube = script.Parent
local Workspace = game.Workspace
mouse = Player:GetMouse()


local SwordFold = game.ReplicatedStorage.Sword


local Sword = {
"Sword"

}


function Click()
while true do
for i,v in pairs(SwordFold:GetChildren())do
if v.Name == Sword[math.random(1, #Sword)] then
wait()
v.Enabled = true
local Gear = v:Clone()
Gear.Parent = Player.Backpack
Sound:Play()
print(Player.Name,"Got", v.Name.."!")
wait()
script.Parent:Destroy()

end
end
end







end




Cube.Activated:connect(Click)
Cube.Equipped:connect(onEquipped)

0
ServerStorage does exist in servers, it's main purpose is to replace the need of Lighting to store objects. ScriptGuider 5640 — 8y
0
Eh, I just recommend not using it. GullibleChapV2 155 — 8y
0
Only Server scripts can access ServerStorage, and it can be used as a secure storage for your models, because client can't access it Mokiros 135 — 8y
Ad

Answer this question