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 5 years ago

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

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

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

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 — 5y
0
how? MOREHOURSOFFUN 104 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 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;

01-- in this example, MyKillBrick is the part you want to do the killing
02function onTouched(part)
03    local hum = part.Parent.Humanoid
04    if hum == nil then
05        local tool =  part:FindFirstAncestorWhichIsA("Tool")       
06        if tool ~= nil then
07    hum = tool.Parent.Humanoid
08        end
09    end
10    print("Good So Far")
11    wait()
12    if hum then
13        hum.Health = 0
14    end
15end
16MyKillBrick.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:

01function onLeft(part)
02    local hum = part.Parent.Humanoid
03    if hum == true then
04        part.Parent.TouchingFloor.Value = false
05    end
06end
07function onTouched(part)
08    local hum = part.Parent.Humanoid
09    if hum == true then
10        part.Parent.TouchingFloor.Value = true
11    end
12end
13script.Parent.TouchEnded:Connect(onLeft)
14script.Parent.Touched:Connect(onTouched)   

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

01while true do
02    wait(0.5)
03    if script.Parent.TouchingFloor.Value == false then
04        repeat
05            x= x + 1
06            wait(0.1)
07        until x == 5 or  script.Parent.TouchingFloor.Value == true
08        if script.Parent.TouchingFloor.Value == false then
09            script.Parent.Humanoid.Health = 0
10        end
11    end
12end

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 — 5y
0
KK. I'm editing answer now Heavenlyblobmaster 271 — 5y
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 — 5y
Ad

Answer this question