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

LocalScript Working Online But Script Isn't Working Online(RemoteEvents, FE)?

Asked by 6 years ago

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?

0
have you checked the server log in the online game JohnJohniamm55 21 — 6y
0
if you mean the Output the yes I have. Wolf5429 15 — 6y
0
There were no errors Wolf5429 15 — 6y
0
Where is the script located? If it's located under the localscript, where is the localscript located? Operation_Meme 890 — 6y
0
The script is located inside the localscript and the localscript is inside the players backpack, the 2 remote events are located inside the localscript as well, I needed to do that instead of putting them in ReplicatedStorage because they would break when i put them in ReplicatedStorage. Wolf5429 15 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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.

0
If you do the welding via the localscript and not with remote events, the sword will only show up for the client. Operation_Meme 890 — 6y
Ad
Log in to vote
0
Answered by
AizakkuZ 226 Moderation Voter
6 years ago

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

0
Also turn off FE to see if that is the problem if it is just tell the script where the RemoteFunction is AizakkuZ 226 — 6y

Answer this question