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:

01script.Parent.Changed:Connect(function()
02    if script.Parent.Visible == true and script.Parent.Position == UDim2.new(0, 0, 0, -3) then
03        wait(1) -- TweenPosition delay
04 
05        wait(0.3)
06 
07        script.Parent.BackgroundColor3 = Color3.new(150, 150, 150)
08 
09        local ServerName
10 
11        local function FindServer()
12            for i, v in pairs(script.Parent.Parent.CurrentServers:GetChildren()) do
13                if v:FindFirstChild("ServerSelected") then
14                    if v:FindFirstChild("ServerSelected").Value == true then
15                        ServerName = v.Name
View all 52 lines...

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:

1Button.MouseButton1Down:Connect(function()
2    RemoteEvent:FireServer()
3end)

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.

1Button1.MouseButton1Down:Connect(function()
2    RemoteEvent:FireServer(1)
3end)
4Button2.MouseButton1Down:Connect(function()
5    RemoteEvent:FireServer(2)
6end)

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

1RemoteEvent.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)
2    if place == 1 then
3        plr.Character.HumanoidRootPart.CFrame = CFrame.new(-- coordinates)
4    elseif place == 2 then
5        plr.Character.HumanoidRootPart.CFrame = CFrame.new(-- other coordinates)
6    -- etc.
7    end
8end)

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

Ad

Answer this question