Coin system gui not working

Hi again everyone i am trying to make a coin system everything works except the gui doesn’t work for some reason
here is my code:

local player = game:GetService("Players"):GetPlayers()
local coin = game.ReplicatedStorage.Coin
local gui = game.StarterGui.ScreenGui.TextLabel
gui.Text = coinsVal.Value
game.Players.PlayerAdded:Connect(function()
	coin.Parent = game.Workspace
	coin.Touched:Connect(function()
		coinsVal.Value = coinsVal.Value + 1
		gui.Text = coinsVal.Value
		coin:Destroy()
	end)
end)

please help if you can because i really need it

1 Like

This line.
Change it from StarterGui to PlayerGui.

I’ll be elaborating right now

local Players = game:GetService("Players")
local coin = game.ReplicatedStorage.Coin


Players.PlayerAdded:Connect(function(Player)
	local clone = coin:Clone()
	clone.Parent = workspace
	local gui = Player.PlayerGui.ScreenGui.TextLabel
	if gui then
		gui.Text = coinsVal.Value
	end
	clone.Touched:Connect(function(hit)
		if Players:FindFirstChild(hit.Parent.Name) then
			coinsVal.Value +=  + 1
			gui.Text = coinsVal.Value
			clone:Destroy()
		end
	end)
end)

I dont see any coinsVal here, so you’d need to define it

it said PlayerGui is not a valid member of Players “Players”
in the output and by the way i don’t want to change my script i just need a fix for the gui

local player = game:GetService("Players")
local coin = game.ReplicatedStorage.Coin


player.PlayerAdded:Connect(function(plr)
	coin.Parent = game.Workspace
    local gui = plr:WaitForChild("PlayerGui").ScreenGui.TextLabel
    gui.Text = coinsVal.Value
	coin.Touched:Connect(function()
		coinsVal.Value = coinsVal.Value + 1
		gui.Text = coinsVal.Value
		coin:Destroy()
	end)
end)

ScreenGui is not a valid member of PlayerGui “Players.LordBoboux.PlayerGui”

local player = game:GetService("Players")
local coin = game.ReplicatedStorage.Coin


player.PlayerAdded:Connect(function(plr)
	coin.Parent = game.Workspace
    local gui = plr:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").TextLabel
    gui.Text = coinsVal.Value
	coin.Touched:Connect(function()
		coinsVal.Value = coinsVal.Value + 1
		gui.Text = coinsVal.Value
		coin:Destroy()
	end)
end)

Tip-
Try to avoid naming objects in names that represent classes [ such as Part ,ScreenGui`, etc]

That works thank you very much for helping me

1 Like

Hey also can you help me with one more thing?
im trying to clone multiple coins and spawn them at random position
it all works but it doesn’t clone it multiple times it just “Teleports it” to different position
code:

local amount = game.ReplicatedStorage.Amount
repeat wait(1)
	coin:Clone()
	local randX = math.random(1, 500)
	local randZ = math.random(1, 500)
	coin.Position = Vector3.new(randX, 1, randZ)
	coin.Parent = game.Workspace
	amount.Value = amount.Value + 1
until
amount.Value == 20

Maybe one of these would help:

Thanks i will try those too :smiley:

local coinClone = coin:Clone()

You forgot to assign the clone to a variable, so you were simply cloning the coin (doing nothing with the clone) and moving the original coin instead.

1 Like

yea that could also be a solution lol.