Tweak16

ROBLOX Scripting | Coins | Server Script

Aug 3rd, 2021 (edited)
1,103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2. Made by Tweakified, Neonblox Games
  3. YouTube Tutorial: https://youtu.be/RM6v_fQKx9w
  4. Discord Support: https://discord.com/invite/JdaFf7p
  5. Local Script: https://pastebin.com/tQrzBpFk
  6.  
  7. Script Type: Regular Script
  8. Script Parent: ServerScriptService
  9. --]]
  10.  
  11. local Players = game:GetService("Players")
  12. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  13.  
  14. local GetCoin = ReplicatedStorage:WaitForChild("GetCoin")
  15. local CoinsFolder = workspace:WaitForChild("Coins")
  16.  
  17. local function NewPlayer(player)
  18.     local leaderstats = Instance.new("Folder") -- include this line if you don't have a leaderboard (remove if not)
  19.     local leaderstats = player:WaitForChild("leaderstats") -- include this line if you already have a leaderboard (remove if not)
  20.     leaderstats.Name = "leaderstats"
  21.     local coins = Instance.new("NumberValue", leaderstats)
  22.     coins.Name = "Coins"
  23.    
  24.     local coindata = Instance.new("Folder")
  25.     coindata.Name = "coindata"
  26.    
  27.     for _, Coin in pairs(CoinsFolder:GetChildren()) do
  28.         local collectedCoin = Instance.new("BoolValue", coindata)
  29.         collectedCoin.Name = Coin.Name
  30.     end
  31.    
  32.     leaderstats.Parent = player
  33.     coindata.Parent = player
  34. end
  35.  
  36. Players.PlayerAdded:Connect(NewPlayer)
  37. for _, player in pairs(Players:GetPlayers()) do
  38.     NewPlayer(player)
  39. end
  40.  
  41. for i, Coin in pairs(CoinsFolder:GetChildren()) do
  42.     Coin.Name = "Coin".. i
  43.     Coin.Touched:Connect(function(hit)
  44.         local char = hit.Parent
  45.         if char ~= nil then
  46.             local player = Players:GetPlayerFromCharacter(char)
  47.             if player ~= nil then
  48.                 local leaderstats = player:FindFirstChild("leaderstats")
  49.                 local coindata = player:FindFirstChild("coindata")
  50.                 if leaderstats ~= nil and coindata ~= nil then
  51.                     local CoinValue = leaderstats:FindFirstChild("Coins")
  52.                     local CollectedCoin = coindata:FindFirstChild(Coin.Name)
  53.                     if CoinValue ~= nil and CollectedCoin ~= nil and CollectedCoin.Value == false then
  54.                         CollectedCoin.Value = true
  55.                         CoinValue.Value = CoinValue.Value + 1
  56.                         GetCoin:FireClient(player, Coin)
  57.                     end
  58.                 end
  59.             end
  60.         end
  61.     end)
  62. end
RAW Paste Data