Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help me with making coin collecting system?

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

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.

9 comments

0

Workspace.Roof.Script:8: attempt to perform arithmetic (add) on Instance and number

0

player.leaderstats.Coins += 120

0

now error is

0

leaderstats is not a valid member of Player "Players.komanos212"

0

can you try player:WaitForChild("leaderstats").Coins += 120

0

now it's Workspace.Roof.Script:8: attempt to perform arithmetic (add) on Instance and number

0

you need to do .Value

0

i forgot to add that, my bad ;-;

0

player.leaderstats.Coins.Value += --whatever amount you want --gives coins

This discussion is preserved as it was. New answers, comments, and votes are closed.