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

How to change leaderstats?

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

✓ Accepted answer
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

1 comment

0

very thank you.

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

1 comment

0

I think it's not necessary to check if it's Humanoid, just check if player then ...

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