Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
ARTEK22 135
8 years ago
Edited 8 years ago

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

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

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
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) ARTEK22 135 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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.

Answer this question