Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with :GetPlayerFromCharacter ?

Asked by 9 years ago

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

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

: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 )
Ad
Log in to vote
0
Answered by 9 years ago

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

0
its a member of players* FauxHawke 0 — 9y
0
There is an Edit feature that allows you to fix typos in your post, just so you know. Perci1 4988 — 9y

Answer this question