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

GetPlayerFromCharacter is not a valid member of Data Model?

Asked by 3 years ago

I have this problem can anyone help me plz here is my code

local TeleportService = game:GetService("TeleportService")
local part = script.Parent



part.Touched:Connect(function(hit)
    local human = hit.Parent:FindFirstChild("Humanoid")
    if human then
        local char = hit.Parent
        local player = game.GetPlayerFromCharacter(hit.Parent) 
        TeleportService:Teleport(7092017722, player)
    end
end)

1 answer

Log in to vote
1
Answered by
NGC4637 602 Moderation Voter
3 years ago

line 10: "local player = game.GetPlayerFromCharacter(hit.Parent)" is wrong

GetPlayerFromCharacter is a function of the player service, not game which is a DataModel.

and most functions use the colon (:) operator and not the dot (.) operator

so replace

local player = game.GetPlayerFromCharacter(hit.Parent)

with

local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

More about GetPlayerFromCharacter

Ad

Answer this question