Ceranity
|
  |
| Joined: 20 Oct 2010 |
| Total Posts: 945 |
|
|
| 06 Apr 2016 05:57 AM |
I have FilteringEnabled on (I need to), but I can't seem to figure out how to get the server to communicate with the client. I want a server script to InvokeClient() when a brick is touched, however it cannot find the player who touched the brick.
What I want to do is to get the serverscript to find the remotefunction within a player's Gui, but it looks as though that filteringenabled does not allow you to get the player that touched a part. If this is the case, how am I supposed to make the server communicate with the client?
script.Parent.Touched:connect(function(touched) local check = touched:GetPlayerFromCharacter() local event = check.PlayerGui.MainGui.BuildingGuis.Restrooms.Walked.Restroom local brick = script.Parent.Parent.WalkTo event:InvokeClient(brick) end) error = GetPlayerFromCharacter is not a valid member of part
I've tried doing:
script.Parent.Touched:connect(function(player) local event = player.PlayerGui.MainGui.BuildingGuis.Restrooms.Walked.Restroom local brick = script.Parent.Parent.WalkTo event:InvokeClient(brick) end)
then I get "player is not a valid member of part"
Can anyone help me?
|
|
|
| Report Abuse |
|
|
|
| 06 Apr 2016 06:01 AM |
script.Parent.Touched:connect(function(touched)
touched is the part that has touched the part that triggers this event(sorry if this sounds confusing :/), so let's say you walked on it and your left leg touched it, your "touched" variable is here the left leg, not the character. So you want to replace this line:
local check = touched:GetPlayerFromCharacter()
with this:
local check = touched.Parent:GetPlayerFromCharacter()
because the character is the parent of that left leg that touched the brick. |
|
|
| Report Abuse |
|
|
Ceranity
|
  |
| Joined: 20 Oct 2010 |
| Total Posts: 945 |
|
|
| 06 Apr 2016 06:06 AM |
Thanks for the reply,
Now it's saying "getplayerfromcharacter() is not a valid member of model" By model is means the parent of the brick that was touched. FilteringEnabled doesn't allow you to get the player who touched a brick it seems. |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2016 06:08 AM |
Oh darn, I made a mistake, you don't use it like that :P
You're supposed to do it like this:
local check = game.Players:GetPlayerFromCharacter(touched.Parent) |
|
|
| Report Abuse |
|
|
Ceranity
|
  |
| Joined: 20 Oct 2010 |
| Total Posts: 945 |
|
|
| 06 Apr 2016 06:13 AM |
Ok so here's what I've done:
script.Parent.Touched:connect(function(touched) local check = game.Players:GetPlayerFromCharacter(touched.Parent) local event = check.PlayerGui.MainGui.BuildingGuis.Restrooms.Walked.Restroom local brick = script.Parent.Parent.WalkTo event:InvokeClient(brick) end)
The error has changed somewhat to "attempt to index local 'check' (a nil value)" |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2016 06:22 AM |
| If you start a server on studio with one player in it and you test it like that, maybe you can check on the server side if you can actually see the players? |
|
|
| Report Abuse |
|
|
Ceranity
|
  |
| Joined: 20 Oct 2010 |
| Total Posts: 945 |
|
| |
|
Ceranity
|
  |
| Joined: 20 Oct 2010 |
| Total Posts: 945 |
|
|
| 06 Apr 2016 07:03 AM |
Bump.
This issue is DEFINITELY down to FilteringEnabled, since it works without it checked. There must be some way to use Touched() with it enabled as a majority of front page games do it. |
|
|
| Report Abuse |
|
|
membra
|
  |
| Joined: 14 Oct 2008 |
| Total Posts: 6313 |
|
|
| 06 Apr 2016 08:50 AM |
GetPlayerFromCharacter will return a player object or nil if there is no player associated with the object in the parameter. Your script always assumes that the object that triggers the event is a player, therefore, ANY part is capable of triggering your event, meaning that if anything other than a player touches the part the 'check' variable will be assigned nil. You could use something like... if game.Players:GetPlayerFromCharacter(touched.Parent) then check = game.Players:GetPlayerFromCharacter(touched.Parent) end
|
|
|
| Report Abuse |
|
|