Why isnt this script working?

local PlayersService = game:GetService(“Players”)
local Workspace = game:GetService(“Workspace”)

local Button = Workspace.Button.Button
local Player1Spawn = Workspace.Spawn1
local Player2Spawn = Workspace.Spawn2
local SpawnLocation = Workspace.SpawnLocation
local Sword = game.ReplicatedStorage.Sword
local GameGui = game.StarterGui.GameGui
local Title = GameGui.Title
local remotePlay = game.ReplicatedStorage.PlaySound

local InRound = false
local cooldown = false

local function StartRound(Player)
local Players = PlayersService:GetPlayers()
if #Players < 2 then
remotePlay:FireClient(Player)
Button.Parent.BillboardGui.TextLabel.Text = “Not enough players”
Button.Parent.BillboardGui.TextLabel.TextColor = BrickColor.new(1, 0, 0)
coroutine.wrap(function()
wait(0.5)
Button.Parent.BillboardGui.TextLabel.TextColor = BrickColor.new(0, 0, 0)
Button.Parent.BillboardGui.TextLabel.Text = “test button”
end)()
return
end

local Player1 = Players[1]
local Player2 = Players[2]

Player1.Character.HumanoidRootPart.CFrame = Player1Spawn.CFrame
Player1.Character.Highlight.OutlineColor = Color3.new(1, 0, 0)
local Player1Sword = Sword:Clone()
Player1Sword.Parent = Player1.Backpack
Player2.Character.HumanoidRootPart.CFrame = Player2Spawn.CFrame
Player2.Character.Highlight.OutlineColor = Color3.new(1, 0, 0)
local Player2Sword = Sword:Clone()
Player2Sword.Parent = Player2.Backpack
InRound = true

local function ended()
print(“ENDED”)
Player1.Character.HumanoidRootPart.CFrame = workspace.SpawnLocation + Vector3.new(0,10,0)
Player2.Character.HumanoidRootPart.CFrame = workspace.SpawnLocation + Vector3.new(0,10,0)
Player1.Character.Highlight.OutlineColor = Color3.new(0, 0, 0)
Player2.Character.Highlight.OutlineColor = Color3.new(0, 0, 0)
Player1Sword:Destroy()
Player2Sword:Destroy()
InRound = false
end

Player1.Character.Humanoid.Died:Connect(ended)
Player2.Character.Humanoid.Died:Connect(ended)
Player1 = nil
Player2 = nil
end

Button.MouseClick:Connect(function(Player)
if InRound == false and not cooldown then
cooldown = true
StartRound(Player)
else
Button.Parent.BillboardGui.TextLabel.Text = “game already in progress”
Button.Parent.BillboardGui.TextLabel.TextColor = BrickColor.new(1,0,0)
remotePlay:FireClient(Player)
coroutine.wrap(function()
wait(0.5)
Button.Parent.BillboardGui.TextLabel.TextColor = BrickColor.new(0, 0, 0)
Button.Parent.BillboardGui.TextLabel.Text = “test button”
end)()
end
coroutine.wrap(function()
wait(0.5)
cooldown = false
end)()
end)

when a player dies its suppose to teleport them both back to spawn but it doesnt why?

1 Like

You’re attempting to teleport them immediately after death. I would assume that because of this, you are trying to teleport them while they are lying on the floor in pieces. Because joints are broken upon death, setting the CFrame of the HumanoidRootPart would not teleport the character, just the HumanoidRootPart. I would recommend using Player.CharacterAdded instead of Humanoid.Died. Player.CharacterAdded will fire when the character respawns, not after they die.

1 Like

This didnt work, but i did come across something and it turns out that the ended print isnt even printing.

also how do i make a button that if the game is in progress they cant join?

stealing my code is ya?! :rage: grrrrr

He’s just padding his post count. Take a look at his post history. He’s been trolling the forums for several years now but never seriously enough that they’ve banned him. Just flag his post if it’s bad enough and block him.

1 Like