I'm making a script where a part will increase its size and while its increasing, it can hurt players the problem is, while its increasing it goes above the player and any other player that touches it. The part is anchored and can collide is false. Why is this happening?
He's a gif so you can see whats happening: https://media.giphy.com/media/T7moZi0R4zX2g/giphy.gif
Code (Local script, starterpack):
local plr = game.Players.LocalPlayer
local stats = plr:WaitForChild("leaderstats")
local e = stats:WaitForChild("EXP")
local d = stats:WaitForChild("damage")
local canfire = true
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Z then
if canfire then
canfire = false
plr.Character.Torso.Anchored = true
local animTrack = plr.Character.Humanoid:LoadAnimation(script.Animation)
animTrack:Play()
local x = Instance.new("Part")
x.Size = Vector3.new(0.5,0.5,0.5)
x.BrickColor = BrickColor.new("Bright blue")
x.Material = "Sand"
x.CFrame = plr.Character.Torso.CFrame + Vector3.new(0,-3,0)
x.Anchored = true
x.CanCollide = false
x.Parent = game.Workspace
for i = 1,25 do
wait(0.01)
x.Size = x.Size + Vector3.new(5,0,5)
end
x.Touched:connect(function(hit)
local ehum = hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
if ehum and ehum ~= plr.Character.Humanoid then
e.Value = e.Value + 1
ehum:TakeDamage(d.Value + 1)
end
end)
plr.Character.Torso.Anchored = false
wait(1)
x:Remove()
canfire = true
end
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

5 comments
sorry that the spacing was not put correct, not sure why it glitched when I clicked post answer
Thanks, that's a way better way of doing that, but I'm still having the same problem. The part still goes above the player while its increasing.
oh, you want the part to not be above the player? I thought you wanted that, I'll edit it!
Okay so now I made it work 3 studs below the torso and remain that way, I think that is what you were trying to do. Accept if it works :)
Thanks my guy, this has been a struggle for a long time. Thank you so much!