I have a LocalScript that contains a Script and 2 RemoteEvents, first is called "Equip" and second is called "UnEquip." I have tried moving the events and the Script to multiple places, ReplicatedStorage, ServerStorage, Lighting even. The LocalScript fires the Equip event when the key "f" is clicked and then in the Script, it should find a model of a Sword in ReplicatedStorage and weld it to the Player's hand. I have found that the problem isn't to do with the LocalScript, I believe it is just a problem with the Script because everything in the LocalScript still runs smoothly and fine. I also went into the normal Play testing in Studio just to see if it worked there, and it does, it just won't work in online servers.
Here is my code:
LocalScript:
local Player = game.Players.LocalPlayer local Character = Player.CharacterAdded:Wait() local mouse = Player:GetMouse() local Equipped = false local UsedOnce = false game:GetService("UserInputService").InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.F and Equipped == false and UsedOnce == false then ---Etc, etc, etc script:WaitForChild("Equip") --Have tried it without WaitForChild as well script.Equip:FireServer() end)
Script:
UsedOnce = false Equipped = false script.Parent.Equip.OnServerEvent:Connect(function(Player) if Equipped == false and UsedOnce == false then wait() Equipped = true Staff = game.ReplicatedStorage.Weapons.Sword:Clone() Staff.Parent = Player.Character Staff:SetPrimaryPartCFrame(Player.Character.LeftHand.CFrame*CFrame.new(0, -0.15, 0)) Staff:SetPrimaryPartCFrame(Staff.Handle.CFrame*CFrame.Angles(math.rad(90), 0, math.rad(90))) Welder = Instance.new("WeldConstraint") Welder.Parent = Staff.Handle Welder.Part0 = Staff.Handle Welder.Part1 = Player.Character.LeftHand ---------------------------------------------------------- elseif Equipped == false and UsedOnce == true then wait() Equipped = true WelderBack:remove() Staff:SetPrimaryPartCFrame(Player.Character.LeftHand.CFrame*CFrame.new(0, 0, 0.2)) Staff:SetPrimaryPartCFrame(Staff.Handle.CFrame*CFrame.Angles(math.rad(-90), math.rad(45), 0)) WelderHand = Welder:Clone() WelderHand.Parent = Staff.Handle WelderHand.Part0 = Staff.Handle WelderHand.Part1 = Player.Character.LeftHand end end) script.Parent.UnEquip.OnServerEvent:Connect(function(Player) if UsedOnce == false then Welder:remove() elseif UsedOnce == true then WelderHand:remove() end wait() Staff:SetPrimaryPartCFrame(Player.Character.LowerTorso.CFrame*CFrame.new(1, 0.5, -2)) Staff:SetPrimaryPartCFrame(Staff.Handle.CFrame*CFrame.Angles(math.rad(25), math.rad(90), 0)) Staff:SetPrimaryPartCFrame(Staff.Handle.CFrame*CFrame.fromOrientation(math.rad(90), 0, 0)) WelderBack = Welder:Clone() WelderBack.Parent = Staff.Handle WelderBack.Part0 = Staff.Handle WelderBack.Part1 = Player.Character.LowerTorso UsedOnce = true Equipped = false end)
Please, any help?
There is your problem. The script won't work because it is located inside a localscript, which is located inside the client. Server scripts cannot run in the client.
To fix this, just do all your welding in the localscript or use remote events, but this time make sure the server script is located inside either Workspace or ServerScriptService.
I think it is that you didn't add in a RemoteFunction or RemoteEvent in ReplicatedStorage I also don't see in the script where you put the RemoteEvents