I am currently making a gun game and a script that is meant to teleport the players when they die is not working properly.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local event = ReplicatedStorage:WaitForChild("PlayerDiedWhileMatchOn")
local value = ReplicatedStorage:WaitForChild("RoundOn")
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, math.min(5, #spawnpoints))
local spawnpnt = spawnpoints[spawnpntnum]
print("yes5")
if character:WaitForChild("Humanoid", 5) then -- the part that doesnt work
local humanoidRootPart = character.HumanoidRootPart
humanoidRootPart.Position = spawnpnt.Position + Vector3.new(0, 3, 0)
print("yes6")
end
end
end
end
end)
this script returns no errors in output and all the prints can be seen in output
this is the local script that fires the event if needed:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
local PlayerDiedEvent = ReplicatedStorage:WaitForChild("PlayerDiedWhileMatchOn")
local function onCharacterAdded(character)
local humanoid = character:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
PlayerDiedEvent:FireServer(LocalPlayer)
end)
end
LocalPlayer.CharacterAdded:Connect(onCharacterAdded)