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

Need help with a lava script please?

This script is supposed to kill people who aren't on a certain team, but it doesn't work

function onTouch(part) 
local humanoid = part.Parent:FindFirstChild("Humanoid") 
if (humanoid ~= nil) then
 if part.Parent.Player.TeamColor ~=  script.Parent.Parent.Parent.Parent.Parent.TeamColor.Value 	then  
	humanoid.Health = 0 -- damage the humanoid
end 
end
end

script.Parent.Touched:connect(onTouch)

errors: TeamColor is not a valid member of Model

1 answer

Player is an ancestor of Character, not the other way. To get a player from a character:

script.Parent.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
if player.TeamColor ~= script.Parent.Parent.Parent.Parent.TeamColor.Value then
-- code
end
end
end)

Formatting tip:

Use tab instead of space bar to format your code. I couldn't do it because I'm on my phone.

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