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
local Player = game:GetService("Players").LocalPlayer;
local PlayerGui = Player:WaitForChild("PlayerGui");
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local StatusBar = PlayerGui:WaitForChild("StatusBar");
local TextLabel = StatusBar:WaitForChild("TextLabel");
local Event = ReplicatedStorage:WaitForChild("Event");
local L_Amount = 14;
local S_Amount = 9;
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;
TextLabel.Changed:Connect(On_Label_Change);
####Server Sided Script
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Event = ReplicatedStorage:WaitForChild("Event");
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)
};
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;
Event.OnServerEvent:Connect(On_Server_Event);
8 comments
you’re handling gui from the server, shouldn’t do that
will that fix the problem?
If I move it to a local script in startergui, it doesnt even work anymore.
That's what i said to him. Completely ignored ;/
So does anyone here know if I can just say "Do this changed event the 1st time, do this one the 2nd?"
OH
TextLabel.Changed:Disconnect() TextLabel.Changed:Connect(function() end) it creates a new connection
You can use characteradded in local script. You cannot use playeradded however.