Stomp not working with magnitude

so im trying to make a enemy stomp and stun towers here is the script EDIT: Forgot some stuff sorry!

local stomp = game.ReplicatedStorage.stomp:Clone()
stomp.Transparency = 0.35
stomp.Parent = workspace
stomp.Position = tower.stomppart.Position
for i,o in pairs(workspace.Towers:GetChildren()) do
        local distance = (tower.PrimaryPart.Position-o.PrimaryPart.Position).Magnitude
        if distance <= 50 and o:FindFirstChild("Stun") and o.PrimaryPart:FindFirstChild("Stun") then
               o.Stunned.Wait.Value = 8.5
               o.Stunned.Value = true
	       o.PrimaryPart.Stun.Enabled = true
        end
end
2 Likes

What’s it not doing specifically? I don’t really see any red flags from looking at your code alone. Can you tell us more about what it isn’t doing and what the end goal is?? :slight_smile:

it might be because im cloning the part? im not sure

No, like, what is the problem you’re facing? What is it supposed to do that it is not doing? What have you tried in regards to fixing this?

Remember that Scripting Support is intended to help you, therefore you need to help us as well by providing necessary information. You should not just be posting code into a thread and saying it does not work; explain how it isn’t working.

i tried using .touched and gettouching parts those wouldn’t work either

Please review my post again as well as the linked category guidelines. You still are not providing enough information on this thread. How is it not working? What is it supposed to do?

1 Like

so i have this part that gets bigger and if a tower is in range it’s supposed to stun it but it doesn’t

i’ve looked up some posts and they dont work. so like the zombie stomps part expands stuns towers is what its supposed to do it might not be working due to engine issues?

A lot of posts here on Scripting Support seem to say that the engine is at fault but a majority of the time it is the developer’s code that is unworking.

You need to review your implementation and apply basic debugging to this problem to attempt to understand where exactly things are going wrong so you can look towards fixes. I do not see any errors with this code so there is something you aren’t providing that is crucial to understanding what is wrong with this system.

ill look for oversights thanks. EDIT: found the bug it was something very stupid but at least i fixed it!

1 Like