Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My script should give money when stepped on a brick but it dosent. Why? EVERYTHING IS NOW SOLVED

Well, the title i could say explained everything, here's the code.

function workended(part)
		local parent = part.Parent
	if game.Players:GetPlayerFromCharacter(parent) then
		parent.Humanoid.Health = 0
		local player = game.Players:FindFirstChild(parent)
		if player then
			player.leaderstats.Money.Value = player.leaderstats.Money.Value + script.Parent.Parent.Value
		end
		end
end

script.Parent.Touched:connect(workended)

And when i step on it i get killed and dont get money. And yes, i checked the value and the value was actually 10 (it was meant to be also) Here's a screenshoot to prove that everything with the leaderstats is fine. http://prntscr.com/ceuw0u

2 answers

✓ Accepted answer

Is there any error?

...Don't use :FindFirstChild to get the player... use :GetPlayerFromCharacter like you almost did.

local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
	hit.Parent.Humanoid.Health = 0
	player.leaderstats.Money.Value = player.leaderstats.Money.Value + script.Parent.Parent.Value
end

1 comment

0

Oh, haha! My terrible mistake. And there was np error at all, The console only just said some yellow text (it displays when you die)

Try BlueTaslem's answer but also try making the leaderstats a folder instead of a model. Not sure if that would make a difference but that did the trick for me one time so It might work for you.

This discussion is preserved as it was. New answers, comments, and votes are closed.