These scripts are used in my video tutorial about how can get coins:
The script named SpinCoin will spin the coins:
1 2 3 4 | while true do wait() script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0.0,0.1,0) end |
The next script for get coin is named GetCoin and has this source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | get_amount = 1 function onTouched(part) local human = part.Parent:findFirstChild("Humanoid") if (human ~= nil) then local player = game.Players:findFirstChild(human.Parent.Name) if (player~=nil) then local stats = player:findFirstChild("leaderstats") if (stats~=nil) then local coins = stats:findFirstChild("Coins") if (coins~=nil) then coins.Value = coins.Value + get_amount end end end script.Parent:remove() end end script.Parent.Touched:connect(onTouched) |
These two scripts will be part of the coin model.
Another script is on ServerScriptService and is named LeaderBoard:
1 2 3 4 5 6 7 8 9 10 11 | print("Hello world! Leaderboard") local coinsManager = require(game.ServerScriptService.ModuleManagerCoins) local function addLeaderToPlayer(player) local stats = Instance.new("Model", player) stats.Name = "leaderstats" local coins = Instance.new("IntValue", stats) coins.Name = "Coins" coins.Value = 0 end game.Players.PlayerAdded:Connect(addLeaderToPlayer) |
The last script module is named ModuleManagerCoins and is used into ServerScriptService to manage coins:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | local module = {} local coins = {} function coinsManager(player) wait() if player:findFirstChild("leaderstats") ~= nil then player.leaderstats:remove() end stats = Instance.new("IntValue") stats.Parent = player stats.Name = "leaderstats" coins = Instance.new("IntValue") coins.Parent = stats coins.Name = "Coins" coins.Value = 0 end game.Players.PlayerAdded:connect(coinsManager) coins = game.Players:GetChildren() for i=1, #coins do coinsManager(coins[i]) end return coinsManager |