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

Did i use GetPlayerFromCharacter() correctly?

Asked by 6 years ago

Script inside workspace:

local humanoid = game.Workspace.Speler.Humanoid
game.Players.PlayerAdded:connect(function(player)
    player = player
end)
humanoid.MaxHealth = 0
humanoid.Health = 0
humanoid.HealthChanged:connect(function(health)

    local players = game:GetService("Players")
humanoid.Parent.Head.Touched:connect(function(otherpart)
if otherpart.Name == "Handle" then
    local character = otherpart.Parent.Parent
    local player = character:GetPlayerFromCharacter()

    local replicatedstorage = game:GetService("ReplicatedStorage")
    local remote = Instance.new("RemoteEvent", replicatedstorage)
    remote:FireClient(player)

end
end)

end)

The error Roblox from Roblox Studio: GetPlayerFromCharacter is not a valid member of Model

I think i used GetPlayerFromCharacter() incorrectly(line 13).

2 answers

Log in to vote
0
Answered by 6 years ago

MachoPiggies is incorrect, and yes, you used it incorrectly. GetPlayerFromCharacter() is a method that can only be called from the Players API:

local player = game.Players:GetPlayerFromCharacter(character)
Ad
Log in to vote
0
Answered by 6 years ago

Use

game.Workspace:GetPlayerFromCharacter(character)

Answer this question