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

Unknown Global variable W001 GetPlayerFromCharacter()?

Hello! I am trying to make a morph pad that requires the player, However when I have GetPlayerFromCharacter() it registers it as a W001 error.

script.Parent.Touched:Connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum ~= nil then
		GetPlayerFromCharacter(hum.Parent)
	end
end)

I also tried using GetPlayerFromCharacter(hit) but it still registers it as a W001.

2 answers

Nevermind, I found a quick solution myself. Here it is for future developers who need something like this.

function getplayer(touched)
	if touched ~= nil then
		local player = game.Players:GetPlayerFromCharacter(touched.Parent)
		if player then
			print(player.Name)	
		end
	end	

end
script.Parent.Touched:Connect(getplayer)

1 comment

0

that is a bad way of doing it, first off touched wont be nil since the event triggered because it was touched, second off connecting the event to a named function like you do it is just stupid, just connect the event directly instead of naming a function

a good way of doing it would be this

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		
	end
end)

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