New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

how do i make it so that when a player walks over a part, they gain a stat in a leaderboard?

Asked by 6 months ago

im trying to make a script where if a player walks over a part, they get +1 gem.

this is my leaderboard script that i currently have:

2 answers

Log in to vote
Answered by 6 months ago

Hello, so make a script or something like that into the player, so into starterplayerscripts and do something like this:

playeradded connect to functin
a = script.Parent.Pa(keep doing .parent until you reach the player).Character(player.Character is character)

if = (name of gem so if name of part is "Gem" then do if hit . name == "Gem") so
if hit.Name == "Gem" then
a.Folderstats whateevr.Gems collected or whatever = a.Folderstats whatever.Gams collected + 1
sorry its sloppy but i needed to hurry CommanderCaubunsia 108 — 6mo
look at it and understand it CommanderCaubunsia 108 — 6mo
Log in to vote
Answered by
roy6576 234 Moderation Voter
6 months ago

Best way is to use a hit detection in the part handled by a server script (not local script):

local DB = false
       local p = game.Players:GetPlayerFromCharacter(hit.Parent)
       if p then
              local stats = p:WaitForChild("leaderstats") 
              local Gems = stats:WaitForChild("Gems") 
              if DB == false then
                     DB = true
                     Gems.Value = Gems.Value + 1
                     --script.Parent:Destroy() --Only if you want it to be one time 
                     DB = false

and that should work. Its advised you set the gems value to something even if 0 when you create it in the leaderboard.

Also sorry its formatted badly. I'm on phone roy6576 234 — 6mo

Answer this question