generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Now Learning about GetPlayerFromCharacter()

Previous Thread :: Next Thread 
Flosky is not online. 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 is not online. 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
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
24 Jul 2013 04:32 PM
GetPlayerFromCharacter is a method. Use a colon. (Players:GetPlayerFromCharacter(Character))
Report Abuse
Flosky is not online. 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 is not online. 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
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
24 Jul 2013 04:33 PM
Also, after you define player, make sure it's not nil. (if Player then)
Report Abuse
Flosky is not online. 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 is not online. 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
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
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
Iterations is not online. Iterations
Joined: 22 Jul 2013
Total Posts: 751
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 is not online. 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 is not online. noah
Joined: 11 Sep 2006
Total Posts: 18977
24 Jul 2013 04:41 PM
Oh shoot, I missed that.
Report Abuse
Flosky is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image