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 make my fireball hit only once so it doesn’t do double the amount of damage.
What is the issue? Include screenshots / videos if possible!
The fireball is hitting more than once.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried using debounce but I don’t really know if I’m doing it right but it still doesn’t help fix the problem.
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!
Hi this is my first post on devforum and I’m a beginner at scripting so I might not understand some stuff.
local Debounce = false
newFireball.Touched:Connect(function(hit)
if hit.Parent.Name ~= player.Name and hit:IsA("BasePart") and hit.Name ~= "Handle" and not Debounce then
Debounce = true
newFireball:Destroy()
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.
Try to use Debounce. Its very helpful to stop things from keep going
@I_lFighter you can do something like this for an example,
local trap = script.Parent
local RESET_SECONDS = 1
local isTouched = false -- Declare debounce variable
local function damagePlayer(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if not isTouched then -- Check that debounce variable is not true
isTouched = true -- Set variable to true
humanoid.Health = humanoid.Health - 10
print("OUCH!")
wait(RESET_SECONDS) -- Wait for reset time duration
isTouched = false -- Reset variable to false
end
end
end
trap.Touched:Connect(damagePlayer)
Thanks, but I don’t know if my script is correct or not but I used debounce and it didn’t work for some reason. Here is my current code (it’s still doing double the dmg when I test it on multiplayer but not when I test it on local player):
local Debounce = false
newFireball.Touched:Connect(function(hit)
if hit.Parent.Name ~= player.Name and hit:IsA("BasePart") and hit.Name ~= "Handle" and not Debounce then
Debounce = true
newFireball:Destroy()
Debounce = false
if not isTouched then -- Check that debounce variable is not true
isTouched = true -- Set variable to true
humanoid.Health = humanoid.Health - 10
print("OUCH!")
wait(RESET_SECONDS) -- Wait for reset time duration
isTouched = false -- Reset variable to false
You didn’t check if Debounce is not true nor did you set it true and wait wait seconds also you didn’t reset it.
I cloned the Fireball and the hitbox and welded them together and made it so that it explodes when the hitbox is touched. But now for some reason it hits the original model of the Fireball instead of the cloned one causing it to explode right in front of where I cast it and when it hits another object. But if I set the CanTouch for the Fireball model to false, I think it most likely caused the fireball to hit twice on one object. I might have gotten a little off topic here but do you know how to solve the issue? (Sorry I’m bad at explaining things sometimes)
I didnt quite understand, forget what I said in the previous message, I ran some tests, and you can remove the “local” from “local Debounce = false” and that will solve
please mark it as a solution if this has helped you. @I_lFighter