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

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

Asked by
NecoBoss 194
10 years ago

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

3 answers

Log in to vote
2
Answered by 10 years ago

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)
0
Thank you. NecoBoss 194 — 10y
1
Accept and upvote my answer if I helped :) Articulating 1335 — 10y
1
I need at least 1 reputation xD NecoBoss 194 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

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.

Log in to vote
0
Answered by 10 years ago

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.

Answer this question