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

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

Asked by 7 years ago

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.

0
OnServerEvent should be OnClientEvent. OldPalHappy 1477 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

0
Reason I got downvoted on this? Snowskateer2 19 — 7y
0
its too short. RubenKan 3615 — 7y
0
I gave him the answer without spoonfeeding him the entire thing... Snowskateer2 19 — 7y
0
Thanks! I put the server-sided script in ServerScriptStorage. After that change, it was working in online mode. hermosavida 6 — 7y
Ad

Answer this question