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

Unknown global: 'hit' in a door script?

local cf = script.Parent.CFrame
script.Parent.Touched:Connect(function(hit) end)
	if hit.Parent.Name == "test key" then
	end 
		script.IsOpening.Value = true
		for i = 1,16 do
			script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, -0.18) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
			wait(0.01)
		end
		script.IsOpening.Value = false
		script.IsOpened.Value = true
	if script.IsOpened.Value == true and script.IsOpening.Value == false then
		script.IsOpening.Value = true
		for i = 1,16 do
			script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.18) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
			wait(0.01)
		end
		script.IsOpening.Value = false
		script.IsOpened.Value = false
		script.Parent.CFrame = cf
		script.CloseSound:Play()
	end
	

while true do end
	wait(15)
	if script.IsOpened.Value == true then
		script.IsOpening.Value = true
		for i = 1,16 do
			script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.18) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
			wait(0.01)
		end
		script.IsOpening.Value = false
		script.IsOpened.Value = false
		script.Parent.CFrame = cf
		script.CloseSound:Play()
	end

in line 3, the "hit" is unknown global, sorry if im stupid im new to scripting :P

2 comments

0

You're ending the function before running code you expect to run inside the function.

0

if i delete the 'end' in the last line it says 'Expected end to close then at line 3, got

2 answers

✓ Accepted answer

From what I can see, you've just ended the function on line 2 before you ran your code. It looks like you've also done the same thing on line 3 and 25 as well.

local cf = script.Parent.CFrame
script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Name == "test key" then
        script.IsOpening.Value = true
        for i = 1,16 do
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, -0.18) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
            wait(0.01)
        end
        script.IsOpening.Value = false
        script.IsOpened.Value = true
    end
    if script.IsOpened.Value == true and script.IsOpening.Value == false then
        script.IsOpening.Value = true
        for i = 1,16 do
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.18) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
            wait(0.01)
        end
        script.IsOpening.Value = false
        script.IsOpened.Value = false
        script.Parent.CFrame = cf
        script.CloseSound:Play()
    end
end)

while true do
    wait(15)
    if script.IsOpened.Value == true then
        script.IsOpening.Value = true
        for i = 1,16 do
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.18) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0)
            wait(0.01)
        end
        script.IsOpening.Value = false
        script.IsOpened.Value = false
        script.Parent.CFrame = cf
        script.CloseSound:Play()
    end
end

1 comment

0

The cframed door goes crazy

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