Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?,

2 comments

0

You can use the event touch ended.

0

how?

1 answer

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

3 comments

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

0

KK. I'm editing answer now

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

This discussion is preserved as it was. New answers, comments, and votes are closed.