My coin system gui doesn't work

I made a coin gui that updates to the amount of coins you have based on an integer value you get coins by killing zombies each zombie gives 5 coins when killed so here where the problem comes in, the integer value never changes even when I kill zombies i have to local scripts for this
local script in zombie’s humanoid

script.Parent.Died:Connect(function()
	game.ReplicatedStorage.Coins.Value += 5
	game.ReplicatedStorage.ZombieAmount.Value -= 1
end)

local script in coins text label

script.Parent.Text = "Coins"
game.ReplicatedStorage.Coins.Changed:Connect(function()
	script.Parent.Text = game.ReplicatedStorage.Coins.Value
end)
1 Like

Is the first script a local script or a server script?

The first script is a local script

Make it a server script, and the issue will be fixed.

ok but won’t that make the coins for everyone? what i mean is for example if a player buys something and it took 100 coins from their coins won’t the other players lose 100 coins? cause its a server script?

if it is a local script then, it is only visible to you. Server replicates in all clients so your coins will be visible trough server.

Does that mean the coins are local?

Are you using Datastores? because it seems like your only using one Value, for litterly every player?

yes

29+1+31-31+68-69+5-4 chars

No, Im not using datastores what do they do?

Dang.

If you’re using ONE VALUE IN REPLICTED STORAGE, it isn’t going to work out chief.

You got to use Datastores to save players data individually, I thought you weren’t because you got a value just in replicated storage.

One value in replicated storage will cause the data to be shared by every player in a server.

Im just trying to make a shop gui when i purchase something in the shop and it takes 100 coins from me when i kill another zombie my coins go back to the same amount they were before i made the purchase i hope you understand

Do you want your player data to save every time they come back? Then you need to use Datastores.

I will but what about the shop thing?

You should have 1 value per player

1 Like

So are you trying to make it so that after a purchase of a specific item in the shop, it takes away 100 coins from xUser, and if they kill xNPC, they get 100 coins?

Here, use datastores and you should figure out the rest

local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local playerData = DataStoreService:GetDataStore("playerData")

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
	
	local data 
	local success, errormessage = pcall(function()
		data = playerData:GetAsync(player.UserId.."-coins") 
	end)
	
	if success then 
		coins.Value = data
	else
		print("Error while getting your data")
		warn(errormessage)
	end
end)

Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		playerData:SetAsync(player.UserId.."-coins", player.leaderstats.Coins.Value)
	end)
	
	if success then
		print("Data successfully saved!")
	else
		print("There was an error while saving the data")
		warn(errormessage)
	end
	
end)

local Players = game:GetService("Players")

local RunService = game:GetService("RunService")

local LocalPlayer = Players.LocalPlayer

local leaderstats = LocalPlayer:WaitForChild("leaderstats")

local Coins = leaderstats:FindFirstChild("Coins")

local Text = script.Parent

RunService.Heartbeat:Connect(function()

Text.Text = "Coins: " .. Coins.Value

end)

No that’s the problem it it gives back the 100 coins they made a purchase with

Where should i put these scripts?

Can we see the full script for reference so that we can assist you with the issue first?

1 Like