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

Why this script works in studio and doesn't work in-game? [Title is specific]

Asked by 6 years ago
Edited 6 years ago

Hello, So I'm trying to make a server selection GUI and I have a GUI of teleportation. If I play in studio it works fine, If I play in-game it doesn't work, It doesn't teleport and the GUI doesn't go away. I don't have any errors on both platforms.

This is the script I'm using:

script.Parent.Changed:Connect(function()
    if script.Parent.Visible == true and script.Parent.Position == UDim2.new(0, 0, 0, -3) then
        wait(1) -- TweenPosition delay

        wait(0.3)

        script.Parent.BackgroundColor3 = Color3.new(150, 150, 150)

        local ServerName

        local function FindServer()
            for i, v in pairs(script.Parent.Parent.CurrentServers:GetChildren()) do
                if v:FindFirstChild("ServerSelected") then
                    if v:FindFirstChild("ServerSelected").Value == true then
                        ServerName = v.Name
                        v:FindFirstChild("ServerSelected").Value = false
                    end
                end
            end
        end

        FindServer()

        if ServerName == "Server1" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-39.109, 0, 104.624) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server2" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-68.079, 0, 133.366) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server3" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-12.131, 0., 104.608) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server4" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-67.991, 0, 104.952) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server5" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-39.931, 0, 133.366) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server6" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-13.286, 0, 133.366) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server7" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-68.079, 0, 160.401) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server8" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-39.676, 0, 160.401) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server9" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-13.541, 0, 160.401) + Vector3.new(0, 50, 0)
        elseif ServerName == "Server10" then
            script.Parent.Parent.Parent.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(-13.541, 0, 186.562) + Vector3.new(0, 50, 0)
        end

        script.Parent:TweenPosition(UDim2.new(2, 0, 0, -3), "Out", "Quad")

        wait(1) -- TweenPosition delay

        script.Parent.Visible = false
    end
end)

I would really appreciate it if you will help me with my problem, Plus I'll accept your answer.

Thanks, MajinBluee

0
I added [Title is specific] so it doesn't annoy me. MajinBluee 80 — 6y
0
Can you fix the script blocks first? Remember that you can use 'Preview'. Also make sure the code is UNDER the ~~~~ and ABOVE the other ~~~~. Don't put the code after the ~~~~. Tymberlejk 143 — 6y
0
Oh, Didn't see that. MajinBluee 80 — 6y
0
Is the game FE? Tymberlejk 143 — 6y
0
Yes MajinBluee 80 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

If you want your button to teleport a player in a FE game you must use separately a LocalScript to handle the button pressing and a server-sided Script to handle the teleporting. In order to make those two scripts talk to each other you need Remote Events. In the LocalScript you need to describe what happens when your button is pressed. We want it to teleport the player, but LocalScripts aren't allowed to do that. And that's where Remote Events come in. You need to fire it.

The LocalScript would look like this:

Button.MouseButton1Down:Connect(function()
    RemoteEvent:FireServer()
end)

But wait! You have multiple places to teleport to. You could use multiple events, but it's better if you just say where to teleport to in the brackets of :FireServer.

Button1.MouseButton1Down:Connect(function()
    RemoteEvent:FireServer(1)
end)
Button2.MouseButton1Down:Connect(function()
    RemoteEvent:FireServer(2)
end)

Now in the Script you need to describe what happens when the Remote Event is fired:

RemoteEvent.OnServerEvent:Connect(function(plr, place) -- the plr stands for the player that fired the event and the place is the number sent with the event (you can name it anything else)
    if place == 1 then
        plr.Character.HumanoidRootPart.CFrame = CFrame.new(-- coordinates)
    elseif place == 2 then
        plr.Character.HumanoidRootPart.CFrame = CFrame.new(-- other coordinates)
    -- etc.
    end
end)

And there you have it. This should work. Hope I helped

Ad

Answer this question