im making a gun game and need help with a script that is meant to teleport people to the selected spawnpart. I need help on finding a way I could do this, I have tried ways and have been at it for hours but cannot find a fix! any help is appreciated.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("PlayerDiedWhileMatchOn")
local value = ReplicatedStorage:WaitForChild("RoundOn")
local spawns = 5
event.OnServerEvent:Connect(function(player)
print("yes")
if value.Value == true then -- checking if round is on
print("yes2")
if player.Character and player.Character:FindFirstChild("Humanoid") then --checking if player
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
print("yes3")
if humanoid.Died then
print("yes4")
local spawnpoints = game.Workspace:WaitForChild("Map").Spawnpoints:GetChildren() -- getting spawnpoints
local spawnpntnum = math.random(1,spawns)
local spawnpnt = spawnpoints[spawnpntnum]
print(spawnpoints)
print(spawnpntnum)
print(spawnpnt)
while true do
if humanoid.Health > 0 then
print("skibii")
if character.HumanoidRootPart then
elseif not character.HumanoidRootPart then
print("here ig")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local spawnpoints = game.Workspace:WaitForChild("Map").Spawnpoints:GetChildren() -- getting spawnpoints
local spawnpntnum = math.random(1,spawns)
local spawnpnt = spawnpoints[spawnpntnum]
end
end
break
end
print("inloop")
wait(0.2)
end
end
end
end
end)