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

Why isnt GetPlayerFromCharacter() working? [closed]

Asked by 10 years ago
local deb = false

script.Parent.Touched:connect(function(hit)
    if deb == false then deb = true
        local char = hit.Parent
        local plr = char:GetPlayerFromCharacter(char)
        if plr:FindFirstChild("Good") then
            if plr.Good.Stolen.Value == true then
                print("Stolen")
            end
        end
    else
        print("Y u n0 w0rk?")
    end
    wait(2)
    deb = false
end)

Locked by NinjoOnline, EzraNehemiah_TF2, Redbullusa, and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

Your problem is that you're attempting to call the GetPlayerFromCharacter() method from the character, whilst it is a method from Players. Use the method off of game.Players to fix(:

local deb = false

script.Parent.Touched:connect(function(hit)
    if deb == false then deb = true
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if plr and plr:FindFirstChild("Good") then
            if plr.Good.Stolen.Value == true then
                print("Stolen")
            end
        end
    else
        print("Y u n0 w0rk?")
    end
    wait(2)
    deb = false
end)
Ad
Log in to vote
2
Answered by 10 years ago
local deb = false

script.Parent.Touched:connect(function(hit)
    if deb == false then deb = true
        local char = hit.Parent
        local plr = game.Players:GetPlayerFromCharacter(char)
        if plr:FindFirstChild("Good") then
            if plr.Good.Stolen.Value == true then
                print("Stolen")
            end
        end
    else
        print("Y u n0 w0rk?")
    end
    wait(2)
    deb = false
end)

Instead of char:GetPlayerFromCharacter(char) you need to do game.Players:GetPlayerFromCharacter(char).