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.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

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. https://gyazo.com/9aae251d787379117dd8605db13d9dc8

this is my leaderboard script that i currently have: https://gyazo.com/9abcc6abbdc98ec2e2f791e7e32e1089

2 answers

Log in to vote
0
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)

a.Touched:coonect(functkion(hit)--variable
if hit.name = (name of gem so if name of part is "Gem" then do if hit . name == "Gem") so
if hit.Name == "Gem" then
gem:Destroy()
a.Folderstats whateevr.Gems collected or whatever = a.Folderstats whatever.Gams collected + 1
0
sorry its sloppy but i needed to hurry CommanderCaubunsia 108 — 6mo
0
look at it and understand it CommanderCaubunsia 108 — 6mo
Ad
Log in to vote
0
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
script.Parent.Touched:Connect(funtion(hit)
       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 
                     wait(1)
                     DB = false
              end
       end
end

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

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

Answer this question