Hello there! I have made a system where people can select a map and play through it. However, I want specific team GUI’s involved- and in this case, the GUI’s that I’m hoping that will disappear aren’t even disappearing! I’d like to change that with a respawn function in my main script.
I want it to where BEFORE the round starts, the player would respawn. I am not too sure on how to go about this, because I also did look up a tutorial on how to do this specific script. I don’t wanna break anything, so what could I do to change the variables around in this script? Just make sure to keep the original names in the script, because I want to make sure I understand every single detail.
local rep = game:GetService("ReplicatedStorage")
local votingSystem = game.Workspace.Voting
local status = rep.Status
local choices = votingSystem:GetChildren()
local maps = rep.Maps:GetChildren()
local intermission = 10
local isAnOption
local randomMap
local chosenMap
local mapClone
-- picking a random map function
local function PickRandomMap ()
local randomNumber = math.random(1, #maps)
randomMap = maps[randomNumber]
return randomMap.CanBeVoted
end
for i, choice in pairs(choices) do
local name = choice.label.SurfaceGui.TextLabel
local picture = choice.Image.SurfaceGui.ImageLabel
isAnOption = PickRandomMap()
if isAnOption.Value == true then
repeat
isAnOption = PickRandomMap()
until
isAnOption.Value == false
name.Text = randomMap.Name
picture.Image = randomMap.Image.Value
randomMap.CanBeVoted.Value = true
else
name.Text = randomMap.Name
picture.Image = randomMap.Image.Value
randomMap.CanBeVoted.Value = true
end
end
rep.InRound.Changed:Connect(function()
if rep.InRound.Value == false then
mapClone:Destroy()
for i, map in pairs(maps) do
map.CanBeVoted.Value = false
end
for i, choice in pairs(choices) do
local name = choice.label.SurfaceGui.TextLabel
local picture = choice.Image.SurfaceGui.ImageLabel
isAnOption = PickRandomMap()
if isAnOption.Value == true then
repeat
isAnOption = PickRandomMap()
until
isAnOption.Value == false
name.Text = randomMap.Name
picture.Image = randomMap.Image.Value
randomMap.CanBeVoted.Value = true
else
name.Text = randomMap.Name
picture.Image = randomMap.Image.Value
randomMap.CanBeVoted.Value = true
end
end
else
local Choice1Votes = #votingSystem.Choice1.button.Votes:GetChildren()
local Choice2Votes = #votingSystem.Choice2.button.Votes:GetChildren()
local Choice3Votes = #votingSystem.Choice3.button.Votes:GetChildren()
if Choice1Votes >= Choice2Votes and Choice1Votes >= Choice3Votes then
chosenMap = votingSystem.Choice1.label.SurfaceGui.TextLabel.Text
elseif Choice2Votes >= Choice1Votes and Choice2Votes >= Choice3Votes then
chosenMap = votingSystem.Choice2.label.SurfaceGui.TextLabel.Text
else
chosenMap = votingSystem.Choice3.label.SurfaceGui.TextLabel.Text
end
status.Value = "The Chosen map is: ".. chosenMap
for i, map in pairs(maps) do
if chosenMap == map.Name then
mapClone = map:Clone()
mapClone.Parent = game.Workspace
end
end
wait(3)
for i, choice in pairs(choices) do
choice.label.SurfaceGui.TextLabel.Text = " "
choice.Image.SurfaceGui.ImageLabel.Image = " "
choice.button.Votes:ClearAllChildren()
rep.VoteReset:FireAllClients(choice.button)
end
local spawns = mapClone.Spawns:GetChildren()
for i, plr in pairs(game.Players:GetChildren()) do
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local humanRoot = char:WaitForChild("HumanoidRootPart")
plr.Team = game.Teams.Playing
humanRoot.CFrame = spawns[math.random(1, #spawns)].CFrame + Vector3.new(math.random(1,4),math.random(1,4),math.random(1,4))
hum.Died:Connect(function()
plr.Team = game.Teams.Lobby
end)
end
end
end)
Now from my general knowledge, I know that this is the spawning point when player(s) make a map vote, and then it teleports them.
local char = plr.Character
local hum = char:WaitForChild("Humanoid")
local humanRoot = char:WaitForChild("HumanoidRootPart")
plr.Team = game.Teams.Playing
humanRoot.CFrame = spawns[math.random(1, #spawns)].CFrame + Vector3.new(math.random(1,4),math.random(1,4),math.random(1,4))
What I WANT TO ACHIEVE is that I want the player to respawn INTO the map, but I have no idea how.
Could anyone show me the right way by showing an example? Please, I am really stumped.
Thank you!