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)
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.
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)