Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to kill player if they aren't standing on a part?

Asked by 4 years ago

local VanFloor = game.Workspace.ucb.vantruck.VanFloor

VanFloor.Touched:Connect(function(itemTouchingPart) print("Item touching part: ", itemTouchingPart)

if(itemTouchingPart.Parent and game.Players:FindFirstChild(itemTouchingPart.Parent.Name))then
    print("There is a player touching the part!") else v.Character.Humanoid.Health = 0
end 

My problem is in v.Character it says v is unknown, how do I define v?,

0
You can use the event touch ended. JesseSong 3916 — 4y
0
how? MOREHOURSOFFUN 104 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You basically want to kill a player if their item is touching a part, right? this is a script to kill the player if either that player or their item is on a part;

-- in this example, MyKillBrick is the part you want to do the killing
function onTouched(part)
    local hum = part.Parent.Humanoid
    if hum == nil then
        local tool =  part:FindFirstAncestorWhichIsA("Tool")        
        if tool ~= nil then
    hum = tool.Parent.Humanoid 
        end
    end
    print("Good So Far")
    wait()
    if hum then
        hum.Health = 0
    end
end
MyKillBrick.Touched:Connect(onTouched)

If this doesnt work or isnt what you intended, comment on this and I'll see what I can do. If it is good, you can accept my answer ;)

IGNORE EVERYTHING BEFORE HERE

EDIT: Try this. Put these 1st script in the part you want and put a BoolValue named "TouchingFloor" in StarterCharacterScripts 1st Script:

function onLeft(part)
    local hum = part.Parent.Humanoid
    if hum == true then
        part.Parent.TouchingFloor.Value = false
    end
end
function onTouched(part)
    local hum = part.Parent.Humanoid
    if hum == true then
        part.Parent.TouchingFloor.Value = true
    end
end 
script.Parent.TouchEnded:Connect(onLeft)
script.Parent.Touched:Connect(onTouched)    

Here is the second script. Put this also in StarterCharacterScripts:

while true do
    wait(0.5)
    if script.Parent.TouchingFloor.Value == false then
        repeat
            x= x + 1
            wait(0.1)
        until x == 5 or  script.Parent.TouchingFloor.Value == true
        if script.Parent.TouchingFloor.Value == false then
            script.Parent.Humanoid.Health = 0
        end
    end
end

This will Punish the player for having none of them touch the floor (or whatever part) for over a 1/2 second. I did this because their animation might have them leave the floor for a split second. Respond if this doesnt work and i'll get back to you ASAP

0
Must,ve worded it badly, my intention is to check if a player is touching a part and if they aren't they die MOREHOURSOFFUN 104 — 4y
0
KK. I'm editing answer now Heavenlyblobmaster 271 — 4y
0
get back to me if it still doesnt work after the edit. Make sure the 1st script is in the part and the second script is in StarterCharacrterScripts and the BoolValue (named "TouchingFloor") is also in StarterCharacterScripts Heavenlyblobmaster 271 — 4y
Ad

Answer this question