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

How to find the wielder of the weapon? [Solved]

So I want to find who's holding a weapon... I put a script inside the handle of the weapon... But would this work?

local human = hit.Parent:findFirstChild("Humanoid")

If there's an easier way, say if I change it the weapon, it won't effect the script, unlike my one, could someone tell me... Because I'm not sure this detects the wielder.

Thanks!

(Would this work)


-- list of account names allowed to go through the door.
permission = { "MasterPoke99" } -- This is how many people can still get through, so u don't have to change shirts. You can also have another friend here. -EDIT

-- TextureId of the VIP shirt.
texture = "http://www.roblox.com" -- EDIT
function checkOkToLetIn(name) 
	for i = 1,#permission do 
		-- convert strings to all upper case, otherwise we will let in 
		-- "Username" but not "username" or "uSERNAME" 
		if (string.upper(name) == string.upper(permission[i])) then return true end 
	end 
	return false 
end 

local Door = script.Parent

function onTouched(hit) 
	print("Door Hit") 
	local human = handle.Parent:findFirstChild("Humanoid") 
	if (human ~= nil ) then 
		if human.Parent.Torso.roblox.Texture == texture then --the shirt 
			Door.Transparency = 0 
			Door.CanCollide = true 
			wait(.1) -- this is how long the door is open 
			Door.CanCollide = true 
			Door.Transparency = 0 
			-- a human has touched this door! 
			print("Human touched Poison Blade") 
			-- test the human's name against the permission list 
		elseif (checkOkToLetIn(human.Parent.Name)) then 
			print("Human passed test") 
			Door.Transparency = 0
			Door.CanCollide = true 
			wait(.1) -- this is how long the door is open
			Door.CanCollide = true 
			Door.Transparency = 0 
		else game.Workspace.Player["Left Arm"].Anchored = true
game.Workspace.Player["Right Arm"].Anchored = true
game.Workspace.Player["Left Leg"].Anchored = true
game.Workspace.Player["Right Leg"].Anchored = true
game.Workspace.Player.Head.Anchored = true
game.Workspace.Player.Torso.Anchored = true
wait(1)
repeat wait() until script.Parent:FindFirstChild("Health") --Wait until it exists.
script.Parent.Parent.Character.Health:destroy() --Destroy it.
game.Workspace.Player.Health:Remove()
repeat wait(1) game.Workspace.Player.Humanoid.Health = game.Workspace.Player.Humanoid.Health-0.1 until nil

		end 
	end 
end 

script.Parent.Touched:connect(onTouched)

-- It's inside a handle, which is inside a gear. I want to make sure it doesn't matter if the gear is in something or not.

1 comment

0

You have not defined handle. It should be handle.Parent.Parent (my typo, apologies). If you define handle then I believe this looks correct

1 answer

✓ Accepted answer

When equipped, a Tool moves into the Character of the wielder.

This would make handle.Parent.Parent the Character of the weapon's wielder.


If hit were the argument of a Touched event, then hit.Parent would who was hit by the weapon, not who held it.

5 comments

0

Ah thanks.

0

Remember to mark answers as accepted so that the question is most clearly resolved...  it should really be the site's job to remind that

0

Yeah I was just seeing it worked before I did it... Can you check if this would work?

0

It should be: Except I had a typo saying handle.Parent: It should be handle.Parent.Parent since handle.Parent is the Tool and the Tool's parent is the Character

0

Ah okay. Thanks I'll test it now.

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