Okay, this is a problem I've been trying to fix for 2 days now, this is the only thing left to do and the game will be finished. I've been really frustrated these days and still am. I really need help.
I've been working on a car game for like a month now. and you can collect coins around the map. The coin script works like this - LocalScript
Clones Coins from ReplicatedStorage
Inside Workspace. When a player touches the coin he is given 10+ cash. But for some reason, after 2 minutes the script somehow breaks and when a player touches a coin everyone in the server gets 10+ cash and the coin disappears on everyone's client. Maybe there is a better way of adding the coins in the workspace?
LocalScript
Inside StarterGui
local Coins = game.ReplicatedStorage:WaitForChild("Coins") local clone = Coins:Clone() local all = clone:GetChildren() clone.Parent = workspace local cash = script.Parent.Parent:WaitForChild("Cash") local sound = script.Parent:WaitForChild("Coin") for i, v in pairs(all) do if v.Name == "CoinGet" then v.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then cash.Value = cash.Value + 10 sound:Play() v:Destroy() end end) end end
The script works fine for the first 2 minutes, gives the player 10+ cash and destroys the collected coin. If you know how to help me please do. this is really frustrating and I want to get over with this. Maybe the script shouldn't be inside StartGui? Maybe the Coins shouldn't be cloned from ReplicatedStorage? Maybe the whole script is poorly written? Please Help.