Variable
Coin GUI
OTHER STUFF
Script inside Screen gui
the reason it doesn’t work is because you have no leaderstats variable
do you know how to make one ? Cant think of one can you give an example ?
game.Players.PlayerAdded:Connect(function(Player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = Player
end)
something like this in a normal script in server script service
you need to parent coins to leaderstats
assuming you have a coins variable,
Coins.Parent = leaderstats
Ok! Do i put that in service script service a long with the script you gave me.
To make it work and add 1 to the gui first what you want to do is create a leaderstats containing the coins:
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = 0
Coins.Parent = leaderstats
end)
This will add a leaderstats to the player and also coins.
Ok moving on to the gui part. Now we will have to detect if the players’ coin variable changed:
local plr = game.Players.LocalPlayer
local Coins = plr:WaitForChild("leaderstats").Coins
local textLabel = script.Parent
Coins.Changed:Connect(function(newVal)
textLabel.Text = "Coins: " .. newVal
end)
This script will be placed under the text label it self. Now moving on to the touched event.
What I like to do is a module called Zone+ since it’s way better at detecting if a player entered an area.
So what you would need to do if go to toolbox and search Models for “ZonePlus”. Insert the Module script into ServerStorage and do the following in a script under ServerScriptService:
local SS = game:GetService("ServerStorage")
local Zone = require(SS:WaitForChild("Zone"))
local partContainer = workspace.Part
local zone = Zone.new(partContainer)
zone.playerEntered:Connect(function(plr)
plr.leaderstats.Coins.Value += 1
end)
This will add 1 to your leaderstats and it will also add 1 to your text label. It worked for me so it should work for you. If you have any questions then you can reply.
Make a new script and In server script storage
game.Players.PlayerAdded:Connect(function(Player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = Player
local coins = Instance.new(“IntValue”)
coins.Name = “Coins”
coins.Value = 0
coins.Parent = leaderstats
end)
Then, if you want it to update every time a part is touched put a script into the part
local Players = game.Players:GetPlayers()
local part = script.parent
local CanGetAPointByTouching = true
part.Touched:connect(function(WhatWasTouched)
local PlayerExists = WhatWasTouched:FindFirstChild(“Humanoid”)
if PlayerExists then
if not CanGetAPointByTouching then return end
CanGetAPointByTouching = false
local Player = Players:GetPlayerFromCharacter(WhatWasTouched.Parent)
local LeaderStats = Player:FindFirstChild(“leaderstats”)
if LeaderStats then
local Coins = leaderstats:WaitForChild(“Coins”)
Coins.Value +=1
Wait(2)
CanGetAPointByTouching = true
end
end
end)
i See ChickHenEn has simplified it will that work?
Get rid of the “end)” in the middle of the script
game.Players.PlayerAdded:Connect(function(Player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = Player
local coins = Instance.new(“IntValue”)
coins.Name = “Coins”
coins.Value = 0
coins.Parent = leaderstats
end)
GeodyEnt will that script work? Compared to JoshLuau?
I haven’t tried it yet. You should probably try since if something goes wrong, we would be fixing one bug on YOUR script, and not on mine.
It’s the same thing but I used zoneplus since it’s better. .Touched will fire mutliple times and not give you what you wanted.
Ok for that do i put it in server script service and delete the script that someone gave me
Don’t delete the other script. I would keep it just in case. Instead, check the “Disabled” box in the properties.
So you think i put it in server script service??
That will fire multiple times and give more than +1 Coins. .Touched is just a bad idea in general.
You can add a simple debounce to fix that. (Which I did in my edit)
You could add Debounce, but there are better ways to do it, like Josh said. Your method is okay though, and would work.