You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
i want to add to an intvalue only once, not twice or more
What is the issue? Include screenshots / videos if possible!
whenever i touch the coin, it adds to my coin value more than once
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
i’ve tried adding debounces and disabling the CanTouch, and looked on the devforums but found nothing that could help
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
this script is supposed to add 1 to an intvalue whenever a coin is touched, then destroy the coin after. for some reason it adds to the intvalue way too many times
local debounce = true
coin2.PrimaryPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == true then
debounce = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local money = player:WaitForChild("Money")
local coined = money:FindFirstChild(coin)
coined.Value += 1
coin2:Destroy()
end
end
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
local debounce = true
coin2.PrimaryPart.Touched:Once(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == true then
debounce = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local money = player:WaitForChild("Money")
local coined = money:FindFirstChild(coin)
coined.Value += 1
coin2:Destroy()
end
end
end
end)
Are you sure there is no 2 models stuck to eachother or smth?
and try this:
local debounce = true
coin2.PrimaryPart.Touched:Once(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == true then
debounce = false
coin2.PrimaryPart.CanTouch = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local money = player:WaitForChild("Money")
local coined = money:FindFirstChild(coin)
coined.Value += 1
coin2:Destroy()
end
end
end
end)
I don’t recommend using :Once as if it was not touched by a character model with a humanoid as a child, it wouldn’t be able to destroy the coin model, as you can only use :Once once, leaving you with another issue.
local debounce = true
coin2.PrimaryPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == true then
print("Touched")
debounce = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local money = player:WaitForChild("Money")
local coined = money:FindFirstChild(coin)
coined.Value += 1
coin2:Destroy()
end
end
end
end)
If it prints Touched more than once, that means something is wrong, if not then the issue is something else.
Would you be able to tell me the current value of the intvalue and what you intend it to be after you have touched the coin?
This is helpful for example as if the current value of the intvalue is 1, and whenever you touched the part you intend it to be 1, as you thought the current value of the intvalue was 0.
However when you have tested it, the intvalue was 2, causing you to think that it added 2.
local Players = game:GetService("Players")
local function leaderboardSetup(player)
local money = Instance.new("Folder")
money.Name = "Money"
money.Parent = player
local pound = Instance.new("IntValue")
pound.Name = "Pound"
pound.Value = 0
pound.Parent = money
end
Players.PlayerAdded:Connect(leaderboardSetup)