Hi! So I made a script where when you step on a trigger part, it anchors your torso, and sends a spike down to kill you. (The spike has its own kill script inside) But I ran into an error. As the spike is moving down, it does not kill the player, but the script does work in other occasions. Here is the script:
local spike = game.ReplicatedStorage.Spike
function descendMovement()
spike.Position = spike.Position - Vector3.new(0, 5, 0)
end
script.Parent.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
print(tostring(hit.Parent).. " touched the Part!")
hit.Parent.Torso.Anchored = true
wait(3)
spike.Position = hit.Parent.Head.Position + Vector3.new(0, 200, 0)
spike.Parent = game.Workspace
while true do
descendMovement()
end
end
end)
function onTouched(hit)
if not hit or not hit.Parent then return end
local human = hit.Parent:findFirstChild("Humanoid")
if human and human:IsA("Humanoid") then
human:TakeDamage(1000)
end
end
script.Parent.Touched:connect(onTouched)
You should ALLWAYS add a wait in a while loop as it will often crash the game also i think it is why it doesn’t work because it may move so fast you can see it due to it
Then it must be the spike that doesn’t work because if the spike touches you and doesn’t kill you it is the spike that is wrong so could you show the code for it?
It does, I tried it in another occasion where I unanchored the spike, and as it hit the floor and bounced up, it killed me. I posted the spike kill script up above
Maybe just set the players Humanoid.WalkSpeed and Humanoid.JumpPower to 0 if the anchoring part is causing issues? This will make it so they can’t move. You could also try anchoring the player’s torso.
So i think the reason is that the player is achored but one solution would be to spawn an invisible box around the player. It won’t be the same effect but i think it might be the easiest.