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

Teleportation Script is No Longer Working /: ?

Asked by 6 years ago
Edited by User#24403 5 years ago

So I have a murder-mystery game, i'm trying to make a script that teleports the player once a TextLabel changes, and then teleports them back to the lobby after it changes back. But for some reason, it will teleport fine, but when it goes to teleport back, it will teleport back to the map spawn point. Can someone look over my script and tell me the cause of this please?

game.Players.PlayerAdded:Connect(function(player)
    while true do
    local Tab = {CFrame.new(-907, 5.4, -307); CFrame.new(-708, 73.4, -338); CFrame.new(-719, 73.4, -243); CFrame.new(-696, 55.4, -288); CFrame.new(-747, 6, -279); CFrame.new(-650, 5, -294); CFrame.new(-712, 8.6, -193); CFrame.new(-903, 5, -425); CFrame.new(-902, 8.6, -176); CFrame.new(-679, 55.4, -366); CFrame.new(-768, 60.2, -394); CFrame.new(-673, 38.6, -373); CFrame.new(-726, 38.6, -253); CFrame.new(-727, 55.4, -330)}
    local locationselected = Tab[math.random(1, #Tab)]
    local Spawnplates = {CFrame.new(19.511, 18.27, -42.511); CFrame.new(-31.86, 18.069, -18.085); CFrame.new(36.297, 19.375, -23.067); CFrame.new(-23.937, 18.17, -34.292); CFrame.new(-7.526, 18.27, -45.252); CFrame.new(-31.86, 18.069, -18.085); CFrame.new(37.096, 18.471, 9.724); CFrame.new(-35.261, 18.471, 2.364); CFrame.new(19.511, 18.27, -42.511)}
    local spawnselected = Spawnplates[math.random(1, #Spawnplates)]
    player.PlayerGui:WaitForChild("statusbar").TextLabel.Changed:Connect(function()
    game.Workspace:WaitForChild(player.Name).Head.CFrame = locationselected
    end)
    player.PlayerGui:WaitForChild("statusbar").TextLabel.Changed:Connect(function()
    game.Workspace:WaitForChild(player.Name).Head.CFrame = spawnselected
end)
    wait()
    end
    end)
0
you’re handling gui from the server, shouldn’t do that User#19524 175 — 6y
0
will that fix the problem? SBlankthorn 329 — 6y
0
If I move it to a local script in startergui, it doesnt even work anymore. SBlankthorn 329 — 6y
1
That's what i said to him. Completely ignored ;/ Delude_d 112 — 6y
View all comments (4 more)
0
So does anyone here know if I can just say "Do this changed event the 1st time, do this one the 2nd?" SBlankthorn 329 — 6y
0
OH User#19524 175 — 6y
0
TextLabel.Changed:Disconnect() TextLabel.Changed:Connect(function() end) it creates a new connection User#19524 175 — 6y
0
You can use characteradded in local script. You cannot use playeradded however. xxXTimeXxx 101 — 6y

1 answer

Log in to vote
1
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
6 years ago
Edited 6 years ago

First off, I want to start by pointing out that your code looks very messy. Indent your code properly.

Here is something you should know about GUI's and Teleportation.

Teleportation should be handled in Server Script and GUI's should be handled in Local Script. In your script, you are trying to do from the Server Script which is not a good idea.

Now, I am not sure what is going on here. I do have couple questions about it that I think you should make clear

  • Are Tab the positions of the places?
  • Are SpawnPoint the spawns of the Tab?

Because you are attempting to randomize both the tables and you are trying to move them to both locations? What do you plan on doing if the both random location are different?

Assuming that Tab is SpawnPoint , I will keep going.


This is a general idea on how your code should look like.

Client Sided Script

-- [Declaration Section]
--\\ Service Stuff
local Player            = game:GetService("Players").LocalPlayer;
local PlayerGui         = Player:WaitForChild("PlayerGui");
local ReplicatedStorage = game:GetService("ReplicatedStorage");

--\\ Your User Interfaces goes here. 
local StatusBar         = PlayerGui:WaitForChild("StatusBar");
local TextLabel         = StatusBar:WaitForChild("TextLabel");

--\\ Remote Event 
local Event             = ReplicatedStorage:WaitForChild("Event");

--\\ Maps Amount Variable; Maximum number of CFrame goes here. 
local L_Amount          = 14;
local S_Amount          = 9;

-- [Processing Section]
local function On_Label_Change ()
    print("Invoked");
    local Num1          = math.random(1, L_Amount); 
    local Num2          = math.random(1, S_Amount);

    if TextLabel.Text  == "Intermission (1 Minute)" then 
        Event:FireServer("Intermission", Num1)
    elseif TextLabel.Text == "Round In Progress (3 Minutes)" then  
        Event:FireServer("Finish", Num2);
    else 
        return;
    end;
end;

-- [Connecting Section]
TextLabel.Changed:Connect(On_Label_Change);

Server Sided Script

-- [Declaration Section]
--\\ Service Stuff
local ReplicatedStorage = game:GetService("ReplicatedStorage");

--\\ Remote Event 
local Event             = ReplicatedStorage:WaitForChild("Event");

-- \\ Your tables; declare here. 
local Locations         = {
     [1] = CFrame.new(-907, 5.4, -307);
     [2] = CFrame.new(-708, 73.4, -338);
     [3] = CFrame.new(-719, 73.4, -243);
     [4] = CFrame.new(-696, 55.4, -288);
     [5] = CFrame.new(-747, 6, -279);
     [6] = CFrame.new(-650, 5, -294);
     [7] = CFrame.new(-712, 8.6, -193);
     [8] = CFrame.new(-903, 5, -425);
     [9] = CFrame.new(-902, 8.6, -176);
    [10] = CFrame.new(-679, 55.4, -366);
    [11] = CFrame.new(-768, 60.2, -394);
    [12] = CFrame.new(-673, 38.6, -373);
    [13] = CFrame.new(-726, 38.6, -253);
    [14] = CFrame.new(19.511, 18.27, -42.511);
};

local Spawnplates       = {
    [1]  = CFrame.new(19.511, 18.27, -42.511); 
    [2]  = CFrame.new(-31.86, 18.069, -18.085); 
    [3]  = CFrame.new(36.297, 19.375, -23.067); 
    [4]  = CFrame.new(-23.937, 18.17, -34.292); 
    [5]  = CFrame.new(-7.526, 18.27, -45.252); 
    [6]  = CFrame.new(-31.86, 18.069, -18.085); 
    [7]  = CFrame.new(37.096, 18.471, 9.724); 
    [8]  = CFrame.new(-35.261, 18.471, 2.364); 
    [9]  = CFrame.new(19.511, 18.27, -42.511)
};
-- [Processing Section]
local function On_Server_Event (Player, Name, Amount)
    local HRP           = Player.Character:WaitForChild("HumanoidRootPart");

    if Name == "Intermission" then 
        print("Intermission");
        if Amount == 1 then 
            HRP.CFrame  = Locations[1];
        elseif Amount == 2 then 
            HRP.CFrame  = Locations[2];         
        elseif Amount == 3 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 4 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 5 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 6 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 7 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 8 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 9 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 10 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 11 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 12 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 13 then 
            HRP.CFrame  = Locations[2];
        elseif Amount == 14 then 
            HRP.CFrame  = Locations[2];
        else 
            return;
        end;

    elseif Name == "Finish" then 
        print("Finish");
        if Amount == 1 then 
            HRP.CFrame  = Spawnplates[1];
        elseif Amount == 2 then 
            HRP.CFrame  = Spawnplates[2];
        elseif Amount == 3 then 
            HRP.CFrame  = Spawnplates[3];
        elseif Amount == 4 then 
            HRP.CFrame  = Spawnplates[4];
        elseif Amount == 5 then 
            HRP.CFrame  = Spawnplates[5];
        elseif Amount == 6 then 
            HRP.CFrame  = Spawnplates[6];
        elseif Amount == 7 then 
            HRP.CFrame  = Spawnplates[7];
        elseif Amount == 8 then 
            HRP.CFrame  = Spawnplates[8];
        elseif Amount == 9 then 
            HRP.CFrame  = Spawnplates[9];
        else 
            print("no");
            return;
        end;
    end;
end;

-- [Connecting Section]
Event.OnServerEvent:Connect(On_Server_Event);
0
I really appreciate clean script. Thank you for promoting it. User#21908 42 — 6y
0
No, Tab is the list of spawnpoints in the MAP, locationselected chooses a random spawnpoint from Tab, Spawnplates is the list of spawnplates, and spawnselected chooses a random spawnplate to send the player back to. SBlankthorn 329 — 6y
0
Do you have discord? SBlankthorn 329 — 6y
Ad

Answer this question