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 but not on server?

Asked by
qwrn12 85
8 years ago
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
        game.Players.Player1.Character.Humanoid:EquipTool(x);
        y = 2
        elseif y == 2 then
        game.Players.Player1.Character.Humanoid: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
        game.Players.Player1.Character.Humanoid:EquipTool(w);
        y = 2
        elseif y == 2 then
        game.Players.Player1.Character.Humanoid:UnequipTools();
        y = 1
        end
    end 
end)

0
First off, you're using Player1, unless your name is Player1 it will not work. Secondly, make sure this is in a LocalScript as you are using UserInputService. M39a9am3R 3210 — 8y
0
ahh qwrn12 85 — 8y
0
how do i get my player? qwrn12 85 — 8y
0
player = game.Players.LocalPlayer koolkid8099 705 — 8y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

You are trying to access game.ServerStorage["Baton"] from the client. Clients do not have access to ServerStorage online. If you intend to have clients accessing an object, store it in ReplicatedStorage so it can be accessed.

Ad

Answer this question