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

Owner only door script?

Asked by
RoyMer 301 Moderation Voter
9 years ago

What's wrong with this? The second function in line 4 is marked in red (in Roblox Studio) and it says: expected identifier, got 'function'?

local Door = script.Parent
local Owner = Door.Parent.OwnerName

function onTouched:connect(function(Hit)
    local Character = Hit.Parent
    local Player = game.Players:GetPlayerFromCharacter(Character)
    if Player and Player.Name ~= Owner.Value then
        Character:BreakJoints()
    end
end

Door.Touched:connect(OnTouched)
1
You do not need the :connect(function(Hit) on line 4, just the function onTouched(Hit) M39a9am3R 3210 — 9y
0
Thanks alot! RoyMer 301 — 9y

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

You're attempting to define an anonymous function while still connecting the function in a connection statement. Just define the function name on line 4.

local Door = script.Parent
local Owner = Door.Parent.OwnerName

function onTouched(Hit)
    local Character = Hit.Parent
    local Player = game.Players:GetPlayerFromCharacter(Character)
    if Player and Player.Name ~= Owner.Value then
        Character:BreakJoints()
    end
end

Door.Touched:connect(OnTouched)
Ad

Answer this question