Flosky
|
  |
| Joined: 15 May 2011 |
| Total Posts: 1815 |
|
|
| 24 Jul 2013 04:29 PM |
Well, now I'm trying to learn about GetPlayerFromCharacter, and I know this time there's an error, because theres a red line under my end. Well..here's my script. Can someone tell me what's wrong and please explain to me what I have to do?
function CreepyMessage(Hit) local g = game.Players.GetPlayerFromCharacter(hit.Parent) local m = Instance.new("Message") m.Parent = g.PlayerGui m.Text = "Working?" wait(3) m:Remove end script.Parent.Touched:connect(CreepyMessage) |
|
|
| Report Abuse |
|
|
noah
|
  |
| Joined: 11 Sep 2006 |
| Total Posts: 18977 |
|
|
| 24 Jul 2013 04:30 PM |
function CreepyMessage(Hit) local g = game.Players.GetPlayerFromCharacter(hit.Parent) if g then local m = Instance.new("Message") m.Parent = g.PlayerGui m.Text = "Working?" wait(3) m:Destroy() end end script.Parent.Touched:connect(CreepyMessage) |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2013 04:32 PM |
| GetPlayerFromCharacter is a method. Use a colon. (Players:GetPlayerFromCharacter(Character)) |
|
|
| Report Abuse |
|
|
Flosky
|
  |
| Joined: 15 May 2011 |
| Total Posts: 1815 |
|
|
| 24 Jul 2013 04:32 PM |
| Can you please explain to me what I did wrong? If I don't know I can't improve. I'm just leanring. |
|
|
| Report Abuse |
|
|
Flosky
|
  |
| Joined: 15 May 2011 |
| Total Posts: 1815 |
|
|
| 24 Jul 2013 04:33 PM |
| Oh I see. I didn't see that. Thanks! |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2013 04:33 PM |
| Also, after you define player, make sure it's not nil. (if Player then) |
|
|
| Report Abuse |
|
|
Flosky
|
  |
| Joined: 15 May 2011 |
| Total Posts: 1815 |
|
|
| 24 Jul 2013 04:35 PM |
| Is that why it still doesn't work? |
|
|
| Report Abuse |
|
|
Flosky
|
  |
| Joined: 15 May 2011 |
| Total Posts: 1815 |
|
|
| 24 Jul 2013 04:36 PM |
Well the end still have a red underscore. This is what I have so far.
function CreepyMessage(Hit) local g = game.Players:GetPlayerFromCharacter(hit.Parent) if g~=nil then local m = Instance.new("Message") m.Parent = g.PlayerGui m.Text = "Working?" wait(3) m:Remove end end script.Parent.Touched:connect(CreepyMessage) |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2013 04:36 PM |
Try this:
function CreepyMessage(Hit) local Player = Game.Players:GetPlayerFromCharacter(Hit.Parent) if Player and Player:FindFirstChild("PlayerGui") then local Message = Instance.new("Message", Player.PlayerGui) Message.Text = "Working?" Game.Debris:AddItem(Message, 3) -- Removes message after three seconds. end end
script.Parent.Touched:connect(CreepyMessage) |
|
|
| Report Abuse |
|
|
|
| 24 Jul 2013 04:37 PM |
Ahh, I see. You did "m:Remove", it's a method. Do: m:Remove() Also, remove is deprecated. Use Destroy. |
|
|
| Report Abuse |
|
|
DrWaffler
|
  |
| Joined: 16 Sep 2011 |
| Total Posts: 4248 |
|
|
| 24 Jul 2013 04:38 PM |
An explanation of your problem,
You had function CreepyMessage(Hit) and GetPlayerFromCharacter(hit.Parent)
one you had capitalized, and another you didn't.
Also, it's usually ALWAYS better to use :Destroy() efficiency wise. |
|
|
| Report Abuse |
|
|
noah
|
  |
| Joined: 11 Sep 2006 |
| Total Posts: 18977 |
|
| |
|
Flosky
|
  |
| Joined: 15 May 2011 |
| Total Posts: 1815 |
|
|
| 24 Jul 2013 04:42 PM |
| Oh. Those would be the two mistakes. Thanks guys! I have to make sure I read my script carefully. |
|
|
| Report Abuse |
|
|