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

Function and player problems?

This is only a snippet, but I'm getting an error on line 4. Worked before, but I replaced the model with a newer version and it broke.

function onTouched(Brick)	
	if enabled == true then
		local Player = Brick.Parent:findFirstChild("Humanoid")
		local Character = game:GetService('Players'):GetPlayerFromCharacter(Player.Parent)

2 answers

✓ Accepted answer

Well, first, your variables are kind of weird. You name the Humanoid variable 'Player', and the Player variable 'Character'. Anyways, you should try this:

function whenTouched(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) then --If it's a player
		local character = hit.Parent
		local humanoid = character:FindFirstChild("Humanoid")
		local player =  game.Players:GetPlayerFromCharacter(character) 
	 end
end)

This way you make sure it's an actual player before defining variables.

"f" seems to be lowercase on line 3. Brick.Parent:FindFirstChild("Humanoid")

1 comment

1

This is a style mistake but not an error.

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