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

.Touched, lag or incorrect firing?

Hello, I have recently been in development of my new place. And I have a very simple kill brick that has this code;

function Kill(Plr)
	game.Players:GetPlayerFromCharacter(Plr.Parent).Alive.Value = false
	Plr.Parent:BreakJoints()
end

script.Parent.Touched:connect(Kill)

The Alive value and such are irrelevant, they do not seem to be creating the fuss. However, sometimes when jumping on a fairly short brick located on top of this kill brick, it will just kill the player anyway. However I've also had scenarios where you can be a few studs above the kill brick, where a death should be impossible to achieve via the kill brick, yet you can still die. This has given me a thought the the script may not be faulty, just the game is lagging. However, I'm clueless on the matter, does anyone have any words of wisdom for this issue?

I wasn't sure if the tag was correct, but it seemed partially relevant, so I used it.

2 answers

✓ Accepted answer

You need to add a debounce, which can be done two ways, a debounce or checking the value in Alive. I am on my phone, so I will post a better version once I get to a computer.

 function Kill(Plr)
  	if game.Players:GetPlayerFromCharacter (Plr.Parent).Alive.Value==true then
  		game.Players:GetPlayerFromCharacter(Plr.Parent).Alive.Value =false
 		 Plr.Parent:BreakJoints()
	end
end

script.Parent.Touched:connect(Kill)

Or...

function Kill(Plr)
	local Debounce = false
		if Debounce == false then
		Debounce = true
		game.Players:GetPlayerFromCharacter(Plr.Parent).Alive.Value =false
		Plr.Parent:BreakJoints()
		wait ()
		Debounce = false
	end
end

script.Parent.Touched:connect(Kill)

Way 1 is recommended so no one can survive when both people touch it.

2 comments

0

Thank you, I completely forgot I needed a debounce. :P The script now pretty much works as it should, and I now think the only cause of the odd deaths I'm having is due to me touching the block, but just not seeing it. Or jumping on rotated blocks that have been CFrame'd into the kill brick cause minor issues. Either way, it works better now, thanks. :)

0

No problem. Comment if you need more help on this issue.

local A = false
script.Parent.Touched:connect(function(Object)
	local Player = game:service'Players':GetPlayerFromCharacter(Object.Parent)
	if Player and not A then
		Player:LoadCharacter()
		A = true
	end
end)

2 comments

0

That answer will still lag since it will can load the character many times in one hit (may touch the part with both legs and more body parts), and does not have the like game.Players:GetPlayerFromCharacter(Plr.Parent).Alive.Value =false

0

Problem solved...

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