Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to refer the player that touched it?

Asked by 10 years ago

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

Log in to vote
0
Answered by
wjs3456 90
10 years ago

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

0
Thanks your makes more sense for me cause I am very new to scripting. TrainerJC999 10 — 10y
Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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)

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

Answer this question