Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

W001: Unkown global 'PlayerTouched', fix?

Asked by 6 years ago
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)
0
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. User#21908 42 — 6y
0
Do you have a discord account? User#21908 42 — 6y
0
Yes, I do, vonotige is dieng#5938 vonotige 49 — 6y
0
mine is PyroPhlegethon#6268 User#21908 42 — 6y
0
I could not find yours. User#21908 42 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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.

0
As for the if statement you created, just put it into the touched function after creating a variable for player. User#21908 42 — 6y
0
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. vonotige 49 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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)
0
1. Nice explanation. 2. findFirstChild and connect are deprecated. Use FindFirstChild and Connect. ee0w 458 — 6y

Answer this question