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

This script doesn't work in servers/studio test severs, anyway to fix this?

Asked by 6 years ago
Edited 6 years ago

the script below for a loadout doesn't work in servers/studio test severs, it usually works in studio

local Weapon = ""
local Storage = game.ServerStorage
Storage:WaitForChild("Odachi")
Storage:WaitForChild("Katana")

function Odachi()
    Weapon = "Odachi"
end
function Katana()
    Weapon = "Katana"
end
function Deploy()
    if Weapon ~= "" then
        local Clone = Storage[Weapon]:Clone()
        Clone.Parent = script.Parent.Parent.Parent.Parent.Backpack
        game.Players.LocalPlayer.PlayerScripts:WaitForChild("CameraScript"):Destroy()
        game.ServerStorage:WaitForChild("CameraScript"):Clone().Parent = game.Players.LocalPlayer.PlayerScripts
        game.Players.LocalPlayer.PlayerScripts.CameraScript.Disabled = false
        script.Parent.Parent:Destroy()
    end
    return
end
script.Parent.Odachi.MouseButton1Click:connect(Odachi)
script.Parent.Katana.MouseButton1Click:connect(Katana)
script.Parent.Deploy.MouseButton1Click:connect(Deploy)

1 answer

Log in to vote
1
Answered by 6 years ago

Your problem is that it is a local script. You can't necessarily access game.ServerStorage with a local script. The reason it works in studio is because in studio, when you click the play button, everything is ran locally. So ServerStorage does work on the client, but in an actual server it doesnt.

A simple fix would be to use ReplicatedStorage instead of ServerStorage.

Hope I helped!

0
thanks KatsuneSniper 31 — 6y
Ad

Answer this question