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

Did i use GetPlayerFromCharacter() correctly?

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

✓ Accepted answer

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)

Use

game.Workspace:GetPlayerFromCharacter(character)

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