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

How to change leaderstats?

Asked by 10 years ago
function onTouched(hit)
    human = hit.Parent:FindFirstChild("Humanoid") 
    if human ~= nil then   
        --I wanna change leaderstats here!!
    end
end

script.Parent.Touched:connect(onTouched)


Hey guys how do I change leaderstats with this script?

its name is stage.

3 answers

Log in to vote
0
Answered by 10 years ago
local Player = game.Players:GetPlayerFromCharacter(hit.Parent) 
--"hit" is the object that hit the part that will change the Leaderstat. It is most likely the leg, so the parent of the leg would be your Character model. We are getting the Player that is connected to this model.

if Player.leaderstats.Stage.Value == script.Parent.Name - 1 then
 -- ensures that if they had skipped one checkpoint, they would not be able to progress.

if human.Health ~= 0 then
 --ensures that the person can't progress if their limb/body part had just landed on the part by  chance when they had died.

Player.leaderstats.Stage.Value = script.Parent.Name
 --Changing the value of the stat. The script's parent (the brick) must be named the stage value you want it to be.

This should work, sorry about explaining in the code, it's just the font is smaller lol. All that would go under the if human ~= nil then statement

0
very thank you. viplav37 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Bump1

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

On Touched:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.leaderstats.CURRENCYNAME.Value = player.leaderstats.CURRENCYNAME.Value + AMOUNT
    end
end)

On Clicked:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    player.leaderstats.CURRENCYNAME.Value = player.leaderstats.CURRENCYNAME.Value + AMOUNT
end)

Thanks Me Later

0
I think it's not necessary to check if it's Humanoid, just check `if player then` ... sswam 0 — 4y

Answer this question