Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with :GetPlayerFromCharacter ?

So I'm trying to build off the the BloxyColaScript in most food gear to add hunger/thirst quenching properties.

When I tried getting player from character (which I'm assuming is tool.parent) It comes with an error

21:33:33.799 - GetPlayerFromCharacter is not a valid member of Model

This is the script:

(The error comes from line 24)

local Tool = script.Parent;

enabled = true




function onActivated()
	if not enabled  then
		return
	end

	enabled = false
	Tool.GripForward = Vector3.new(0,-.759,-.651)
	Tool.GripPos = Vector3.new(1.5,-.5,.3)
	Tool.GripRight = Vector3.new(1,0,0)
	Tool.GripUp = Vector3.new(0,.651,-.759)


	Tool.Handle.DrinkSound:Play()

	wait(3)
	
	local player = Tool.Parent:GetPlayerFromCharacter(character)
	local thirst = player.PlayerGui.Thirst
	
	if (thirst ~= nil) then
				print("The player is here!")
	else  print ("Player not here :(")
		
		end
	end

	Tool.GripForward = Vector3.new(-.976,0,-0.217)
	Tool.GripPos = Vector3.new(0.03,0,0)
	Tool.GripRight = Vector3.new(.217,0,-.976)
	Tool.GripUp = Vector3.new(0,1,0)

	enabled = true



function onEquipped()
	Tool.Handle.OpenSound:play()
end

script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

I'm testing it out by printing if player is there or not, but it doesn't print

2 answers

✓ Accepted answer

:GetPlayerFromCharacter is a member of the Players service, not of models.

Also note that you never defined the variable character but tried to use it.


Try

local character = tool.Parent
local player = game.Players:GetPlayerFromCharacter( character )

GetPlayerFromCharacter() isn't a member of a model, its a member of player. So use game.Players:GetPlayerFromCharacter(Tool.Parent) I hope this helped.

2 comments

0

its a member of players*

0

There is an Edit feature that allows you to fix typos in your post, just so you know.

This discussion is preserved as it was. New answers, comments, and votes are closed.