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!
When a Axe hits the tree I want to find the player who used the axe and increase a leaderstat
What is the issue? Include screenshots / videos if possible!
I couldn’t find anything about this.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I couldn’t find anything about this.
local x = z.Part
local y = z.TreeMeshTop
local debounce = false
local hits = 0
local hitsN = 8
x.Touched:Connect(function(hit)
if hit.Parent.Name == "Axe" then
if not debounce then
debounce = true
hits = hits + 1
wait(2)
debounce = false
if hits == hitsN then
hits = 0
x.Anchored = false
y.Anchored = false
y.CanCollide = false
wait(4)
x:Destroy()
y:Destroy()
local tree = game.ServerStorage["Animated Tree"]:Clone()
tree.Parent = game.workspace
wait(0.01)
z:Destroy()
end
end
end
end)
This is the current script (Server Script) inside the tree.
I don’t think this is a tool script, since there are no references to any of the events shared by Tool instances.
local z = script.Parent --im assuming this is the scripts parent
local x = z.Part
local y = z.TreeMeshTop
local debounce = false
local hits = 0
local hitsN = 8
local players = game:GetService("Players")
x.Touched:Connect(function(hit)
if debounce then
return
end
if hit.Parent.Name == "Axe" then
local char = hit.Parent:FindFirstAncestorOfClass("Model")
local plr = players:GetPlayerFromCharacter(char)
local leaderstats = plr:WaitForChild("leaderstats")
local stat = leaderstats:WaitForChild("Stat") --change to name of stat
stat.Value += 1 --change value by amount (you can move this to later inside the callback function if necessary)
debounce = true
hits += 1
task.wait(2)
debounce = false
if hits == hitsN then
hits = 0
x.Anchored = false
y.Anchored = false
y.CanCollide = false
task.wait(4)
x:Destroy()
y:Destroy()
local tree = game.ServerStorage["Animated Tree"]:Clone()
tree.Parent = game.workspace
wait(0.01)
z:Destroy()
end
end
end)
To the original poster, I had to define something for the variable named “z” because before it was undeclared, you should probably change what I used however (I just guessed that it might be the script’s parent).
Thank you, It works! But I don’t really understand what the task in wait() is for, can you please explain?
Also sorry I accidentally didn’t include the z variable in the paste