pwnionJoin Date: 2017-01-03 Post Count: 117 |
I'm using triggers in my game that affect the player by inserting localscripts and/or removing them. How do I get the player from touching a part? |
|
|
You could use this
script.Parent.Touched:connect(function(touch)
local human = touch.Parent:FindFirstChild("Humanoid")
if human then
local char = human.Parent
local player = game.Players:GetPlayerFromCharacter(char)
end
end) |
|
pwnionJoin Date: 2017-01-03 Post Count: 117 |
script.Parent.Touched:connect(function()
--I can't do anything here since idk how to get the player
end) |
|
|
I think this?
(in the part)
script.Parent.Touched:connect(function(hit)
if hit.Parent.Humanoid ~= nil then
--do stuff with him
end
end) |
|
|
Use the script I posted.
script.Parent.Touched:connect(function(touch)
local human = touch.Parent:FindFirstChild("Humanoid")
if human then
local char = human.Parent
local player = game.Players:GetPlayerFromCharacter(char)
end
end) |
|
pwnionJoin Date: 2017-01-03 Post Count: 117 |
My bad I was a little impatient there and I thought people might've not understood the question. |
|
|
@hollowtommy221
What are all the variables for? Just assign a variable to the result of GetPlayerFromCharacter; if it returns nil, then don't do anything.
|
|
pwnionJoin Date: 2017-01-03 Post Count: 117 |
Thanks hollowtommy221! |
|
|
@Unsubtleties
IDK. I just typed it without studio for a quick answer. |
|
|
script.parent.Touched:connect(function(whateveryouwanthereitdoesntmatter)
local player = whateveryouwantitdoesntmatter.parent
end) |
|
pwnionJoin Date: 2017-01-03 Post Count: 117 |
Wouldn't this be the same thing?
script.Parent.Touched:connect(function(touch)
local char = touch.Parent
if char then
local player = game.Players:GetPlayerFromCharacter(char)
end
end) |
|
|
No. "if char then" would also be entirely useless in that situation. You would want to check for player, not char.
|
|
pwnionJoin Date: 2017-01-03 Post Count: 117 |
Ahhh everybody's talking at once it makes my replies seem incoherent |
|
|
What specific part of the player are you looking for? or are you just testing to see if it is a player? |
|
pwnionJoin Date: 2017-01-03 Post Count: 117 |
script.Parent.Touched:connect(function(touch)
local char = touch.Parent
local player = game.Players:GetPlayerFromCharacter(char)
end)
This?
|
|
|
pwnionJoin Date: 2017-01-03 Post Count: 117 |
I'm just trying to get the player so I can insert localscripts. |
|
|
Just use the Touched event locally then.
|
|
|