Have a script where adds +1 to gui when touching coin. After touching it once though i need it destroyed. Did the basic destroy script but not working.
Server Script service script:
Coins GUI script
Starter character scripts local script
Have a script where adds +1 to gui when touching coin. After touching it once though i need it destroyed. Did the basic destroy script but not working.
Server Script service script:
Coins GUI script
What exactly do you want destroyed? The coin, the script, the points, the ability of the coin to add to the next person touching it?
Also, hard to read scripts where you use variables that are the same name as the item they represent.
For example:
local coins = Player:waitForChild("leaderstats").Coins
so that you can do
coins.Value = coins.Value +1
I want the coins to get destroyed when humanoid touches part.
x = x + 1
can become x += 1
, and a = a * b
can become a *= b
while true do
loop with a wait()
inside. It is a terrible mistake and you will find out why when you learn more about Luau.Coins
in the TextLabel Coins
in your .Changed
connection in the GUI script. You just do script.Parent.Text
.Coin:Destroy()
. This makes all references to it nil
however, so make a presence check before you do anything with it.game:GetService()
to guarantee it will be available.StarterCharacterScripts
script, just to make it more maintainable and readable.StarterCharacterScripts
should preferably be in StarterPlayerScripts
, as it will otherwise reset when the character resets.Instead of making the coin transparent, then having Coin.CanTouch = false
set to true, why not just use Coin:Destroy()
Make this a script inside of the coin (server script)
local coin = script.Parent
coin.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent) or game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
if plr then
plr.leaderstats.Coins.Value += 1
coin:Destroy()
end
end)
In a local script, it won’t actually add to the coin value.
Thank you all, i will try right now, thanks for your time.
Thank you so much it worked!!!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.