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

Help me with making coin collecting system?

Asked by 2 years ago

How to make that if so me o n e to u che s the ro o f the n i t g i v e s c o i n s? P l e a s e h e l p.

Scripts: (all in s e r v e r s c r i p t s e r v i c e) local DataStoreService = game:GetService("DataStoreService") local CoinsStore = DataStoreService:GetDataStore("CoinsStore")

game.Players.PlayerAdded:Connect(function(player)

local leaderstats = Instance.new("Folder") --making leaderstats
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local Coins = Instance.new("IntValue") --making coins
Coins.Name = "Coins"
Coins.Parent = leaderstats

local UserId = player.UserId

local data

local success, errormessage = pcall(function() --getting loaded data
    data = CoinsStore:GetAsync(UserId)
end)

if success then
    Coins.Value = data
end

end)

game.Players.PlayerRemoving:Connect(function(player) local UserId = player.UserId local data = player.leaderstats.Coins.Value

CoinsStore:SetAsync(UserId, data)

end)

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
local roof = game.Workspace.Roof --wherever roof is for you
local debounce = false
local reset_seconds = 1
roof.Touched:Connect(function(hit) --when roof is touched
    if hit.Parent:FindFirstChild("Humanoid") and debounce == false then --checks if its player
        debounce = true
        local player = game.Players[hit.Parent.Name] --gets player
        player.leaderstats.Coins += --whatever amount you want --gives coins
        wait(reset_seconds)
        debounce = false
    end
end)

well you can do this

this basically checks if its player that touched roof and then gives coins, have not tested code, sorry if there are errors.

0
Workspace.Roof.Script:8: attempt to perform arithmetic (add) on Instance and number komanos212 2 — 2y
0
player.leaderstats.Coins += 120 komanos212 2 — 2y
0
now error is komanos212 2 — 2y
0
leaderstats is not a valid member of Player "Players.komanos212" komanos212 2 — 2y
View all comments (5 more)
0
can you try player:WaitForChild("leaderstats").Coins += 120 Sabailuridze 126 — 2y
0
now it's Workspace.Roof.Script:8: attempt to perform arithmetic (add) on Instance and number komanos212 2 — 2y
0
you need to do .Value kodymarcey 49 — 2y
0
i forgot to add that, my bad ;-; Sabailuridze 126 — 2y
0
player.leaderstats.Coins.Value += --whatever amount you want --gives coins kodymarcey 49 — 2y
Ad

Answer this question