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

Players tool is only supposed to take tool when he jumps out but isn't. Any help? I accept answers.

So I've been working on this for two straight days and have still yet to figure it out. I've tried multiple codes, they all have failed and have tried others code too. They failed also. I want the players tool to be taken away only when he jumps out of the seat and not the first time he sits in it.

local DeBounce = true

local function takeWeapon(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	print(player)
	local backpack = player.Backpack
	if backpack:FindFirstChild("AssaultRifle")then
		local rocket = backpack:FindFirstChild("AssaultRifle")
		wait(1)
		if backpack == nil then
			rocket:Destroy()
		end
	end
end
script.Parent.TouchEnded:Connect(takeWeapon)

1 comment

0

you are using touch detection for a seat?

2 answers

✓ Accepted answer

you can use

seat.Occupant

. Basically it detects the occupant of a seat and then to detect the character sit you can use

Humanoid.Sit 

2 comments

0

This is the code I've created and it works! I'll just improve it and work on any issues that come up! Thank you!

0

great gl

local DeBounce = true

local function takeWeapon(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local backpack = player.Backpack
	local playerHumanoid = hit.Parent:FindFirstChild("Humanoid")
	wait(.1)
	if playerHumanoid.Sit == false then
		local rocket = backpack:FindFirstChild("AssaultRifle")
		rocket:Destroy()
	end
end
script.Parent.TouchEnded:Connect(takeWeapon)

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