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

Leaderstat value add when part is being touched?

Asked by
Drakyd 1
4 years ago
Edited 4 years ago

Hello guys. Please help me, I am really new to scipting and I can't figure how to do it. I would like to make a reward system (which I made) and count coins. you start at 0 and when you do a parkour you get reward. For example you touch the part and you teleport (which I could get to work) and then you get +10 points. My points are called Tree Tokens on the leaderboard and here is the teleport script I would like to import the coin add script into:

script.Parent.Touched:connect(function(hit) 
 if hit.Parent:FindFirstChild('Humanoid') then 
  hit.Parent.Head.CFrame = CFrame.new(-58.5, 6.55, -63.5)

 end
end)

I used this to make the leaderstats:

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CompleteSaveSystem")
local ds2 = datastore:GetDataStore("TTSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "leaderstats"
 local Complete = Instance.new("IntValue", folder)
 Complete.Name = "Completes"
 local TT = Instance.new("IntValue", folder)
 TT.Name = "Tree Tokens"

 Complete.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, Complete.Value)

 TT.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, TT.Value)

 Complete.Changed:connect(function()
  ds1:SetAsync(plr.UserId, Complete.Value)
 end)

 TT.Changed:connect(function()
  ds2:SetAsync(plr.UserId, TT.Value)
 end)
end)

0
Is your "Tree Tokens" leaderstat an IntValue? If so, you can add game.Players(hit.Parent.Name).leaderstats:FindFirstChild("Tree Tokens").Value = game.Players(hit.Parent.Name).leaderstats:FindFirstChild("Tree Tokens").Value + 10. Does that help at all? OswinFalls 69 — 4y
0
It says Drakyd is not a valid member of Players Drakyd 1 — 4y
0
Oops! It should be [ ] instead of ( ) --------- game.Players[hit.Parent.Name].leaderstats:FindFirstChild("Tree Tokens").Value = game.Players[hit.Parent.Name].leaderstats:FindFirstChild("Tree Tokens").Value + 10 OswinFalls 69 — 4y
0
Thank you! It adds the points, but the problem is it adds it 6-10 times. so you get 60-100 points. Could you help me out with this? (Tries wait(5) but won't help) Drakyd 1 — 4y
View all comments (3 more)
0
Sure, You'll want to add a debounce system so that it only registers once. Basically that means creating an "if" statement with a local variable saying whether or not the button was recently pressed. Here's a whole article about it: https://developer.roblox.com/en-us/articles/Debounce OswinFalls 69 — 4y
0
Thank you I made it! :) Drakyd 1 — 4y
0
Answer something so I can mark you as helper Drakyd 1 — 4y

Answer this question