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

Why is this VIP Door Local Script not Functioning?

I have made a VIP Door script in which if a person's torso is wearing a certain decal it allows them to enter a door. If they are not wearing the suitable decal the person who tries to enter the door dies. This LocalScript inside a door is not functioning at all. It doesn't kill or open the door. What are the errors in this script?

local Door = script.Parent

function onTouch(brick)
	local Player = brick.Parent:findFirstChild("Humanoid")
	if (Player ~= nil) then
		if Player.Parent.Torso.roblox.Texture =="rbxassetid://2166863805" then
			Door.CanCollide = false
			Door.Transparency = 1
		else
			Player.Health = Player.Health - 110
		end
	end
end

Door.Touched:Connect(onTouch)

1 answer

✓ Accepted answer

###This is happening because LocalScripts do not run in Workspace. They only run in:

  • PlayerGui

  • PlayerScripts

  • Backpack

  • Player's Character

  • ReplicatedFirst

###You could either switch to a Script or place the LocalScript into one of those five places. I'd recommend switching to a Script.

local Door = script.Parent

local function onTouch(brick)
    local Player = brick.Parent:FindFirstChild("Humanoid") -- findFirstChild deprecated 
    if Player then -- ~= nil and brackets are irrelevant 
        if Player.Parent.Torso.roblox.Texture =="rbxassetid://2166863805" then
            Door.CanCollide = false
            Door.Transparency = 1
        else
            Player.Health = Player.Health - 110
        end
    end
end

Door.Touched:Connect(onTouch)

1 comment

0

Thanks!

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