So originally Someone would step on the block and not gain any money. Now I'm at the point where they gain money but can keep gaining it. I need the person to gain it once. This code is put on a Checkpoint block made by Roblox so some of the code is Checkpoint code. Thankyou in Advance
This is the leaderboard, the name of the currency is "ObbyBucks<|>"
game.Players.PlayerAdded:connect(function(p)
local stats = Instance.new("IntValue")
stats.Name = "leaderstats"
stats.Parent = p
local money = Instance.new("IntValue")
money.Name = "ObbyBucks<|>"
money.Value = 100
money.Parent = stats
end)
Next is The code that makes the level variable. I'll tell you about it later.
game.Players.PlayerAdded:connect(function(p)
local stats1 = Instance.new("IntValue")
stats1.Name = "touch"
stats1.Parent = p
local money1 = Instance.new("IntValue")
money1.Name = "levelup"
money1.Value = 1
money1.Parent = stats1
end)
Last is the code put on the checkpoint block. My plan to keep them to <|>10 per level completion was to create a variable, called "levelup", child to "touch". Checkpoint one would only give them money if the variable, stored under the player, was 1. Checkpoint # 2 was only going to give them money if they're level 2 variable was 2 and would up the variable to 3 after giving them the money. etc. Any other ideas are appreciated
local myspawn = script.Parent
local serverStorage = game:GetService('ServerStorage')
local function award(player, level, bucks)
local stats = player:findFirstChild('touch')
local Money = player:findFirstChild("leaderstats")
local EarnMoney = Money and Money:findFirstChild('ObbyBucks<|>')
local levelStat = stats and stats:findFirstChild('levelup')
if levelStat then
levelStat.Value = levelStat.Value + level
if EarnMoney then
EarnMoney.Value = levelStat.Value + bucks
end
end
end
myspawn.Touched:Connect(function(hit)
if hit and hit.Parent and hit.Parent:findFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local checkpointData = serverStorage:findFirstChild("CheckpointData")
if not checkpointData then
checkpointData = Instance.new("Model", serverStorage)
checkpointData.Name = "CheckpointData"
end
local checkpoint = checkpointData:findFirstChild(tostring(player.userId))
if not checkpoint then
checkpoint = Instance.new("ObjectValue", checkpointData)
checkpoint.Name = tostring(player.userId)
player.CharacterAdded:connect(function(character)
wait()
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
HumanoidRootPart.CFrame = serverStorage[tostring(player.userId)].Value.CFrame
+ Vector3.new(0, 4, 0)
end)
end
checkpoint.Value = myspawn
award(player, 10, 1)
end
end)

3 comments
I just use .Changed then based on what checkpoint they've gotten to, reward the player. Its much cleaner than all of this mess.
You can edit your original question to adhere to more tasks, rather than double posting.
Thanks for the advice, the problem is I'm new to Roblox scripting. So it would be hard for me to figure out how to script it.