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

How do I make an object add 1 point on a leaderboard when someone touches it?

I'm not really sure where to start. Would I use onTouch function?

3 answers

Place this in the part that you want to be touched:

script.Parent.Touched:connect(function(hit) --When the part is touched.
    if debounce then
        return nil
    end
    local Player = Game.Players:GetPlayerFromCharacter(hit.Parent)
    if Player then --If it was a Player that touched.
        debounce = true
	Player.leaderstats.Points.Value = Player.leaderstats.Points.Value + 1
        wait(1)
	debounce = false
    end
end)

3 comments

0

Thank you.

1

Accept and upvote my answer if I helped :)

1

I need at least 1 reputation xD

Simple, really.

function touched(hit)
if hit.Parent:findFirstChild("Humanoid") then
local plr=game.Players:GetPlayerFromCharacter(hit.Parent)
plr.leaderstats.Points.Value=plr.leaderstats.Points.Value+1
end
end
script.Parent.Touched:connect(touched)

This script will check to make sure it's a person, and then add +1 to points.

Yes. It would look kind of like this.

local function(onTouch)
	game.Players.PlayerAdded:connect(function(player)
	
            	Player.leaderstats.Money.Value = Player.leaderstats.Money.Value +1
end

Keep in mind that this is a rough representation, it may/may not work in game.

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