Hi, I’m new to scripting. Currently I want my script to only give 10 coins to leaderstats, however even with my debounce included. It records the mouseclicked event 1-20 times when i’ve just clicked it once, therefore giving the player anywhere from 10 coins to 200.
local spawn1 = game.Workspace.SpawnLocation
–local appleparts = apple:GetChildren()
while true do
task.wait(3)
local apple1 = game.Workspace.AllApples:GetChildren()
for _, v in pairs (apple1) do
if v:IsA(“Model”) then
local apple = v:GetChildren()
local debounce = true
for _, v1 in pairs (apple) do
if v1:IsA(“MeshPart”) and debounce ~= nil then
v.ClickDetector.MouseClick:Connect(function(plr)
local debounce = false
print (“MouseClicked1”)
v1.Anchored = false
v1.AssemblyLinearVelocity = Vector3.new(10,25,0)
local humanoid = plr.Character:WaitForChild(“Humanoid”)
local animate = humanoid:WaitForChild(“Animator”)
local kickanimation = Instance.new(“Animation”)
kickanimation.AnimationId = “rbxassetid://16826458454”
local kickanimationtrack = animate:LoadAnimation(kickanimation)
kickanimationtrack:Play()
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 10
for _, v in pairs (apple) do
if v:IsA("MeshPart") then
task.wait(3)
v.Parent:Destroy()
break
end
end
local debounce = false
task.wait(1)
end)
end
end
end
end
end