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

Owner only door script?

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)

2 comments

1

You do not need the :connect(function(Hit) on line 4, just the function onTouched(Hit)

0

Thanks alot!

1 answer

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)

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