Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Only works in studio?

I made this long script, and it only works in studio....

Player = game.Players.LocalPlayer
Cube = script.Parent
local Workspace = game.Workspace
mouse = Player:GetMouse()
function onEquipped()
Cube.Handle.Equipped:Play()	
end

local GearFolder = game.ServerStorage.SwordsFolder


local MovementGearNames = {
"BlackAndWhiteWingedSword",
"BombosSurvivalKnife",



}


function Click()
while true do
for i,v in pairs(GearFolder:GetChildren())do
if v.Name == MovementGearNames[math.random(1, #MovementGearNames)] then
wait(0.01)
v.Enabled = true
local Sound = Instance.new("Sound",script.Parent.Handle)
Sound.SoundId = "rbxassetid://163362522"
Sound.Volume = 1
Sound.Pitch = 1
Sound.Looped = false
Sound.Name = "GearSound"
local Gear = v:Clone()
Gear.Parent = Player.Backpack
Sound:Play()
print(Player.Name,"Got", v.Name.."!")
wait(0.01)
script.Parent:Destroy()

end
end
end


		




end




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

3 answers

Problem

The only problem I can see is that since it works in studio and not in server it should be a latency problem, this happens because in studio everything is pretty much local so you don't have to wait for a server to create stuff so your local scripts run instantly. In server this doesn't happen as when a local scripts cause upons something in player or character that is server-sided then the local script is "local" which makes it run faster then the server can respond.

Solution

repeat wait() until game.Players.LocalPlayer.Character--To the top of every local script

1 comment

0

Well i did put the code that you said on top of the local script, but it didnt work.

repeat wait() until game.Players.LocalPlayer.Character

I was experiencing this problem too. I was wondering what was going on and I will edit in a fix when I find one! Also in online mode do F9 or fn+F9 if F9 colored the same as the fn key and it will show the output. That might help you.

This discussion is preserved as it was. New answers, comments, and votes are closed.