player=game.Players.LocalPlayer y = 1 x = game.ServerStorage["Baton"]:Clone(); game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.E then if y == 1 then player:EquipTool(x) y = 2 elseif y == 2 then player:UnequipTools() y = 1 end end end) w = game.ServerStorage["BillyClubRiotShield"]:Clone(); game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Q then if y == 1 then player:EquipTool(w) y = 2 elseif y == 2 then player:UnequipTools() y = 1 end end end)
nothing that i do is working please help this worked on serverscript service then i changed it to a localscript and it broke
There are two issues with your script. First of all, you should change
player=game.Players.LocalPlayer
to:
local player=game.Players.LocalPlayer
Using local variables has many benefits; try to change all of your non-local variables to local variables.
The main issue is that you can't access anything in ServerStorage
from a LocalScript. LocalScripts run on the client. Anything in ServerStorage
can only be accessed from the server, using a Script
, rather than a LocalScript
. However, you can't use UserInputService
from a Script
. You should probably look into RemoteEvents and RemoteFunctions to remedy this conflict.
Good luck! I hope this helps.