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

Unknown global: 'hit' in a door script?

Asked by 6 years ago
Edited by OldPalHappy 6 years ago
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

0
You're ending the function before running code you expect to run inside the function. OldPalHappy 1477 — 6y
0
if i delete the 'end' in the last line it says 'Expected end to close then at line 3, got <eof> EnerKenji517 -3 — 6y

2 answers

Log in to vote
0
Answered by
Troidit 253 Moderation Voter
6 years ago
Edited 6 years ago

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
0
The cframed door goes crazy EnerKenji517 -3 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

when i did it, and touched it the door gets crazy

Answer this question