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

How to refer to the Player with a Variable?

How to use a variable to find the player?

If you can fix this code please do it!

local Part = (The Part)
local PlayerName = (String Value)

Part.Touched:Connect(function(hit)
	local Player = hit.Parent
	game.Players. -- How to use the variable to find the player
end

please continue the script for me!

1 answer

local Part = (The Part)
local PlayerName = (String Value)

Part.Touched:Connect(function(hit)
	local char = hit:FindFirstAncestorOfClass("Model")
	if char and char:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(char)
	end
end)

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