Hello! So, I'm making a coin system in my game (a game that simulates a race). I created a part of a coin and added a counter. But now I would like to make these coins (part) appear randomly through the race and keep moving (example: left, right, up and down), and I would also like to know how I save this information so that the player does not lose his money when he leaves the game
accountant script:
game.Players.PlayerAdded:Connect(function(plr) local paste = Instance.new("Folder",plr) paste.Name = 'leaderstats' local money = Instance.new("IntValue",paste) money.Name = 'money' end)
coins(part) script:
local debounce = false script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') then if debounce == false then debounce = true local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.leaderstats.money.Value = player.leaderstats.money.Value + 1 script.Parent:Destroy() end end end)
Put this is ServerScriptService and make it a Script
while true do local pos1 = math.random(-512,512) --Make the number smaller so that It can fit in your Baseplate(X and Z axis) local pos2 = math.random(-512,512) --Make the number smaller so that It can fit in your Baseplate(X and Z axis) local part = game.Workspace.YourPart --Change the name to your part part.Position = Vector3.new(pos1, 21, pos2) --Change 21 to make it lower or higher(Y axis) end
Tell me if there is any problems, If it works please Approve it.