Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't my script work in online mode but will work in studio? What am I doing wrong?

I'm trying to make a teleport which is FE compatible. When I tested it in studio, it worked, but going in-game, it doesn't. Is there something I'm doing wrong?

local player = game.Players.LocalPlayer
local char = player.Character

script.Parent.MouseButton1Click:connect(function(mouse)
        game.ReplicatedStorage:WaitForChild("Teleport"):FireServer()
    end)

game.ReplicatedStorage:WaitForChild("Teleport").OnServerEvent:connect(function()
    if script.Parent.Clicked.Value == false then
        char.Torso.CFrame = CFrame.new(Vector3.new(245.826, 77.351, 13.6))
        script.Parent.Clicked.Value = true
        script.Parent.Text = "Teleport to Runway"        
    elseif script.Parent.Clicked.Value == true then
        char.Torso.CFrame = CFrame.new(Vector3.new(26.8, 74.977, 41.499))
        script.Parent.Clicked.Value = false
        script.Parent.Text = "Teleport to Island"
    end
end)

"Teleport" is currently a RemoteEvent.

1 comment

0

OnServerEvent should be OnClientEvent.

1 answer

✓ Accepted answer

ServerEvents don't fire to localscripts. You'll need to put them in seperate scripts, one being server-sided. Only ClientEvents will fire to a localscript, so you'd need to change it to OnClientEvent for it to work

4 comments

0

Reason I got downvoted on this?

0

its too short.

0

I gave him the answer without spoonfeeding him the entire thing...

0

Thanks! I put the server-sided script in ServerScriptStorage. After that change, it was working in online mode.

This discussion is preserved as it was. New answers, comments, and votes are closed.