Cash drops when player dies and when clicked not giving cash to player who clicked it

when the player die’s a part comes out their head and when you click it its supposed give you cash but when I click it, it doesn’t give me cash or an error

(the script is in serverscriptservice)

2 Likes

Why are you trying to get the player variable when you already have it bro

2 Likes

You’re getting the player twice? you don’t need to get another player, you already have a parameter for that.

If your still having issues, put a print statement inside the function and see if it runs.

Also your code is just a big brick(no offense)
I barely could even read it. Clean the code up, separate the lines, and use an early exit kind of style that uses not and return.

i added the characteradded so it can find the character model, so it can find the head

I mean in the click detector, does it fire?

when you click the part it does destroy it but it doesn’t give you cash

Put a print statement in the statement where its supposed to give you money, does it print?

nope i added a print statement and it did not print

Why are you re-assigning the player to another variable? Just use the parameter.

if plr and plr:FindFirstChild("leaderstats") then
plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value+10
end

Also put a print statement after the Humanoid check and see if it prints.

1 Like

i added these variables so it can find the character and find its head of the player

Did you add my previous code? You should be using the player of the clickDetector event not the player added event.

oh ok ill do that and also it added the print statement and it did find the humanoid

1 Like

I pretty sure the mouse click paramter gives you the player not an object of it so you dont need to be doing plr.parent just do plar.leaderstats…

Hi! The problem is at 15 and 16 lines

15 - Player don’t have humanoid, only player’s character has it.
16 - You’re reassigning player variable to Players service. You you don’t need to do that

Here’s improved code:

local cash = game.ReplicatedStorage.thecash

game.Players.PlayerAdded: Connect(function(player) 
	player.CharacterAdded: Connect(function(character) 
		local hum = character:WaitForChild("Humanoid") hum.Died: Connect(function()
			local cashClone = cash:Clone()
			cashClone.CFrame = character.Head.CFrame
			cashClone.Parent = workspace
			print("works")
			local clickDetector = Instance.new("ClickDetector")
			clickDetector.Parent = cashClone
			clickDetector.MouseClick:Connect(function(plr)
				if plr and plr: FindFirstChild("leaderstats") and plr.leaderstats: FindFirstChild("Cash") then
					plr.leaderstats.Cash.Value += 10
				end
				cashClone:Destroy()
			end)
		end)
	end)
end)
1 Like

He’s checking for the character. Not the player. Well ig ur right.

At line 15 hes checking if players serivce has got a humanoid and of course it doesn’t so he should plr.character

Player is already an object, you can see it in game → Players

1 Like

thank you so much! and also thank you skellyton for helping me!

1 Like