local Brick = script.Parent
game.Players.PlayerAdded:Connect(function(player)
if not player:IsInGroup(157764) then
local function PlayerTouched(Part)
local Parent = Part.Parent
if game.Players:GetPlayerFromCharacter(Parent) then
Parent.Humanoid.Health = 0
end
end
end
end)
Brick.Touched:connect(PlayerTouched)
W001: Unkown global 'PlayerTouched', fix?
2 answers
Your issue is one of scope. The function is defined locally inside of a block of code. This means that your code will only see that function inside of the block that it was defined in. Here is my best explanation of scope. I don't know what you're trying to do, but because you have the :GetPlayerFromCharacter() you don't need it inside the PlayerAdded event. In fact, you are just creating additional unnecessary events every time a new player joins. I recommend putting the function outside of the PlayerAdded event. I hope this helps and have a great day scripting! Note: read the link I posted to more clearly understand how scope works.
2 comments
As for the if statement you created, just put it into the touched function after creating a variable for player.
I'm trying to make a group only door, if you're not in the group it kills you, it would be nice if you could help me out.
function onTouched(hit)
if hit.Parent:findFirstChild("Humanoid") then
if not hit.Parent:IsInGroup(157764) then
hit.Parent.Humanoid:TakeDamage(100)
end
end
end
script.Parent.Touched:connect(onTouched)
1 comment
- Nice explanation. 2. findFirstChild and connect are deprecated. Use FindFirstChild and Connect.
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
If one of the answers helped you out please accept their answer. It is considered a courtesy and shows the community you no longer need help.
Do you have a discord account?
Yes, I do, vonotige is dieng#5938
mine is PyroPhlegethon#6268
I could not find yours.