Why won't my script work?

So I’m trying to have it so that when you equip a weapon, it waits until you have died to equip it. But this script doesn’t seem to be working. The print statement is not going off.
Script:

local button = script.Parent
local player = game:GetService("Players").LocalPlayer
button.Activated:Connect(function()
	game.ReplicatedStorage.EquippingNextRound:Fire()
	player.CharacterAdded:Wait()
	print("Equipping Baseball Bat.")
end)

I can provide any other necessary scripts etc. just ask.

Try debugging to see if the event is even firing.

local button = script.Parent
local player = game:GetService("Players").LocalPlayer
print("Found Player")
button.Activated:Connect(function()
    print("Activated")
	game.ReplicatedStorage.EquippingNextRound:Fire()
print("Fired")
	player.CharacterAdded:Wait()
	print("Equipping Baseball Bat.")
end)

All of the print statements are firing, just seems to be the equipping one that isn’t.

Your main goal in here is to EQUIP the bat when player DIES right?

Equip the bat once the player respawns after dying, yes.

Can you try replacing the CharacterAdded delay with a task.wait(1)? I would love to see if the problem is an infinite yeild.

Hello Batmanissupercoolbro,

based on your explanations and past posts I’m guessing you want to give a player a bat when they die.

Firstly, to check if a Humanoid (player) is dead, you use Humanoid.Died. Here is an example:

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			print(player.Name .. " has died!")
		end)
	end)
end)

The code below would print the player’s name, followed by “has died!”, whenever a player dies. For example, if the player was named “Batmanissupercoolbro”, “Batmanissupercoolbro has died!” would be printed to the output when you died.

Secondly, to equip a tool to a player you should get the bat you plased in your game (like in ReplicatedStorage or ServerStorage), and parent it to the players backpack.
This is an example on what I mean:

local bat = game.ReplicatedStorage:WaitForChild("Bat")
bat:Clone().Parent = player.Backpack

This is a script inside the ‘StarterGui’ container meaning that it’s being cloned into the local player’s ‘PlayerGui’ container each time their character is added/loaded.

Move the script to the StarterPlayerScripts container and reference the gui from there.

1 Like

I was wondering if it was this that was the problem.
But here’s the script I have, and it isn’t working.

local button = game.StarterGui.EquipTools.ToolsPage.ScrollingFrame.Weapons.bat.TextButton
local player = game:GetService("Players").LocalPlayer

button.Activated:Connect(function()
	game.ReplicatedStorage.EquippingNextRound:Fire()
	print("activated")
	player.CharacterAdded:Connect(function()
		print("Equipping Baseball Bat.")
	end)
	print("script finished")
end)