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

How to refer the player that touched it?

Oh so I am new to scripting and I need to know how to refer to the player who touched it and do it to him.

local D = Workspace.D

function onTouch(part)
game.Workspace.Player1.Head:Destroy()
end

D.Touched:connect(onTouch)

And one more thing what do you refer to as Right or left arm in roblox scripting

2 answers

✓ Accepted answer

I *believe * you refer to person who touched it as the parent. So in your case:

game.Workspace.PARTNAMEHERE.Parent.Head:Destroy()

Also try the FindFirstChild method. So:

arm = game.Workspace.PARTNAMEHERE.Parent:FindFirstChild("Right Arm")
arm:Destroy()

I hope this works

1 comment

0

Thanks your makes more sense for me cause I am very new to scripting.

To refer to a name with a space, we use square brackets ([ and ]) to index instead of a dot (.), and then the string of the name:

person["Name With Space"]
-- vs
person.NameWithoutSpace

The part that touches us can be a leg or an arm or the head or torso. Those parts make up what a player's Character. Once we get the Character, we can grab the corresponding Player.

local D = Workspace.D

function onTouch(part)
	game.Workspace.Player1.Head:Destroy()
	character = part.Character
	if character then
		player = game.Players:GetPlayerFromCharacter( character )
		if player then
			-- It is a player
			-- (as opposed to some other random object hitting it)
			character.Head:Destroy()
		end
	end
end

D.Touched:connect(onTouch)

1 comment

0

Ok, dont know a thing I better stick to something else until I find some more about scripting I started 2 days ago.

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