Advertisement
OnFireRobloxScriptin

Touch to collect coin (Respawn Version)

Jul 7th, 2024
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. --//Variables
  2. local coin = script.Parent --Variable for coin
  3. local touched = false --Variable for a debounce
  4.  
  5. coin.Touched:Connect(function(hit)
  6.     if not touched then --Checks if the debounce variable is set to false
  7.         touched = true --Debounce variable set to true
  8.         if hit.Parent:FindFirstChild("Humanoid") then --Checks for players
  9.             local char = hit.Parent --Gets character
  10.             local player = game:GetService("Players"):GetPlayerFromCharacter(char) --Gets player
  11.             local leaderstats = player:FindFirstChild("leaderstats") --Find leaderstats
  12.             if leaderstats then --Checks for leaderstats
  13.                 leaderstats.Cash.Value += 50 --Give Cash
  14.             end
  15.             coin.Transparency = 1 --Makes coin invisible
  16.             coin.CanCollide = false --Nothing can touch the coin
  17.             task.wait(10) --Wait 10 seconds, change 10 to # of seconds you want to wait
  18.             coin.Transparency = 0 --Makes coin visible
  19.             coin.CanCollide = true --Coin can be touched again
  20.         end
  21.         touched = false --Debounce variable set to false
  22.     end
  23. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement