No errors but doesn’t work?

Alright, so the issue is my script is not working but there are no errors to me and it looks fine. It only works suddenly only sometimes and when it does something weird happens with it too, im trying to make it that multiple people in a certain team have a weld on them when they join a team. The weld script works btw, I don’t know the issue, heres the script

local kb = game.ReplicatedStorage.KillBrick:Clone()
local killerteam = game:GetService("Teams")["Killer"]

wait(3)
game.Players.PlayerAdded:Connect(function(play)
  play.CharacterAdded:Connect(function(player)
    if play.TeamColor == killerteam.TeamColor then
        local character = play.Character or play.CharacterAdded:Wait()
        kb.Parent = character
        local weld = Instance.new("WeldConstraint")
        weld.Parent = character
        weld.Part0 = kb
        weld.Part1 = character.HumanoidRootPart
        kb.Position = character.HumanoidRootPart.Position
        kb.IsInUse.Value = true
           end
       end)
end)

PlayerAdded event works only when player join, so you have wait(3) before event so it not register that you are joined.

1 Like

Do you want to clone the KillBrick every time when a player character respawns? Also, the first parameter of the CharacterAdded event is the recently added character, so i dont see a point of making another variable for the character.

Try using this code for your script:

local killerteam = game.Teams:WaitForChild("Killer")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		if player.TeamColor == killerteam.TeamColor then
			local kb = game.ReplicatedStorage.KillBrick:Clone()
			kb.Parent = character
			local weld = Instance.new("WeldConstraint")
			weld.Parent = character
			weld.Part0 = kb
			weld.Part1 = character.HumanoidRootPart
			kb.Position = character.HumanoidRootPart.Position
			kb.IsInUse.Value = true
		end
	end)
end)