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

Admins, remove this question?

Asked by
Muoshuu 580 Moderation Voter
10 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I can't find these bugs, hoping you guys will be able to. This is in a Local Script, in the Player's PlayerGui

A - It won't show notes upon aiming at doors, though if E is press, acts like normal (Still no note) B - Won't Examine objects

Here is an image of the Hierarchy - http://prntscr.com/3cg8fm

wait(.1)
local Player=game.Players.LocalPlayer
repeat wait() until Player.Character and Player.PlayerGui
local Camera=workspace.CurrentCamera
local Mouse=Player:GetMouse()
local Gui=Instance.new("ScreenGui",Player.PlayerGui) Gui.Name="Target" local T=Instance.new("TextLabel",Gui) T.Size=UDim2.new(1,0,.035,0) T.Position=UDim2.new(0,0,.7,0) T.Text="" T.TextColor3=Color3.new(255,255,255) T.TextWrapped=true T.TextScaled=true T.BackgroundTransparency=1
local Enabled=true
local Crouching=false
Player.CameraMode="LockFirstPerson"
Player.Character.Humanoid.WalkSpeed=12

for i,v in pairs(Player.Character:GetChildren()) do
    if v.ClassName=="Part" then
        v.Transparency=1
    elseif v.ClassName=="Pants" or v.ClassName=="Shirt" or v.ClassName=="Hat" or v.ClassName=="CharacterMesh" then
        v.Parent=nil
    end
end

Mouse.Move:connect(function()
    local Target=Mouse.Target
    if Target~=nil then
        Target=Target.Parent
        if Target==nil then return end
        Target=Target.Parent
        if Target==nil then return end
        local Mag=9
        if Target.Name=="Door" then
            Mag=(Player.Character.Torso.Position-Target.Main.Position).magnitude
        elseif Target.Name=="Examine" then
            Mag=(Player.Character.Torso.Position-Target.Body.Torso.Position).magnitude
        end
        if Mag<=8 then
            if Target.Name~="Examine" and Target.Name~="Door" then return end
            if Enabled==false then return end
            if Target.Name=="Examine" and Target.Examinable.Value==false then return end
            T.Text="Press E to "..Target.Type.Value.."..."
        elseif Mag>8 then
            if Enabled==false then return end
            T.Text=""
        end
    elseif Target==nil then
        if Enabled==false then return end
        T.Text=""
    end
end)


Mouse.KeyDown:connect(function(k)
    k=k:lower()
    if k=="e" then
        if Enabled==false then return end
        local Target=Mouse.Target
        if Target==nil then return end
        Target=Target.Parent
        if Target==nil then return end
        local Mag=9
        if Target.Name=="Door" then
            Mag=(Player.Character.Torso.Position-Target.Main.Position).magnitude
        elseif Target.Name=="Examine" then
            Mag=(Player.Character.Torso.Position-Target.Body.Torso.Position).magnitude
        end
        local N=Target.Parent.Name
        if Mag<=8 then
            if N=="Examine" then
                Target=Target.Parent
                if Target.Examinable.Value==false then return end
                Enabled=false
                Camera.CameraType="Scriptable"
                Camera.CameraSubject=Target
                Camera.CoordinateFrame=Target.Cam.CFrame
                Camera.Focus=Target.Body.Torso.CFrame
                Player.Character.Humanoid.WalkSpeed=0
                T.Text=Target.Text.Value
                for i,v in pairs(Target.Items:GetChildren()) do
                    local C=game.ReplicatedStorage:FindFirstChild(v.Value)
                    if C~=nil then
                        C=C:Clone()
                        local C1=C:Clone()
                        C.Parent=Player.StarterGear
                        C1.Parent=Player.Backpack
                        for k,l in pairs(C:GetChildren()) do
                            if l.ClassName=="Part" then
                                l.Anchored=false
                            end
                        end
                        for k,l in pairs(C1:GetChildren()) do
                            if l.ClassName=="Part" then
                                l.Anchored=false
                            end
                        end
                    end
                    v.Parent=nil
                end
                Target.Rem.Parent=nil
                wait(2)
                Camera.CameraType="Custom"
                Camera.CameraSubject=Player.Character.Humanoid
                Player.Character.Humanoid.WalkSpeed=12
                T.Text=""
                Target.Examinable.Value=false
                Enabled=true
            elseif Target.Name=="Door" then
                if Target.Lock.Value==true then
                    Enabled=false
                    T.Text="This door is locked! Find a key to open it."
                    wait(2)
                    Enabled=true
                    return
                end
                if Target.Open.Value==true then return end
                Target.Open.Value=true
                for i=1,78 do
                    wait()
                    Target.Main.CFrame=Target.CFrame*CFrame.new(0,-.1,0)
                end
                wait(2)
                for i=1,78 do
                    wait()
                    Target.Main.CFrame=Target.CFrame*CFrame.new(0,.1,0)
                end
                wait(1)
                Target.Open.Value=false
            end
        end
    elseif k=="c" then
        if Crouching==false then
            --_G.Crouch(true)
            Crouching=true
        elseif Crouching==true then
            --_G.Crouch(false)
            Crouching=false
        end
    end
end)

Mouse.Button1Down:connect(function()
    local Target=Mouse.Target
    if Target==nil then return end
    Target=Target.Parent
    if Target==nil then return end
    Target=Target.Parent
    if Target==nil then return end
    if Player.Character:FindFirstChild("Key") then
        if Target.Name=="Door" then
            if Target.Lock.Value==true then
                if Player.Character.Key.Handle.BrickColor==Target.DoorColor.Value then
                    Enabled=false
                    T.Text="Successfully opened door!"
                    Target.Lock.Value=false
                    Player.Character.Key.Parent=nil
                    wait(1.5)
                    Enabled=true
                    T.Text=""
                elseif Player.Character.Key.Handle.BrickColor~=Target.DoorColor.Value then
                    Enabled=false
                    T.Text="This key does not fit the keyhole!"
                    wait(1.5)
                    Enabled=true
                    T.Text=""
                end
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

Every change I made:

wait(0.1)
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character and Player.PlayerGui
local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()

local Gui = Instance.new("ScreenGui", Player.PlayerGui)
Gui.Name = "Target"
local T = Instance.new("TextLabel", Gui)
T.Size = UDim2.new(1, 0, 0.035, 0)
T.Position = UDim2.new(0, 0, 0.7, 0)
T.Text = ""
T.TextColor3 = Color3.new(1, 1, 1)
T.TextWrapped = true
T.TextScaled = true
T.BackgroundTransparency = 1

local Enabled = true
local Crouching = false
Player.CameraMode = "LockFirstPerson"
Player.Character.Humanoid.WalkSpeed = 12

for i,v in pairs(Player.Character:children()) do
    if v.ClassName == "Part" then
        v.Transparency = 1
    elseif v.ClassName == "Pants" or v.ClassName == "Shirt" or v.ClassName == "Hat" or v.ClassName == "CharacterMesh" then
        v.Parent = nil
    end
end

Mouse.Move:connect(function()
    local Target = Mouse.Target

    if Target then
        Target = Target.Parent
        if not Target then return end
        Target = Target.Parent
        if not Target then return end
        local Mag = 9

        if Target.Name == "Door" then
            Mag = (Player.Character.Torso.Position - Target.Main.Position).magnitude
        elseif Target.Name == "Examine" then
            Mag = (Player.Character.Torso.Position - Target.Body.Torso.Position).magnitude
        end

        if Mag <= 8 then
            if Target.Name ~= "Examine" and Target.Name ~= "Door" then return end
            if Target.Name == "Examine" and not Target.Examinable.Value then return end
            if not Enabled then return end

            T.Text = "Press E to " .. Target.Type.Value .. "..."
        elseif Mag > 8 then
            T.Text = ""
        end
    elseif not Target then
        if not Enabled then return end
        T.Text = ""
    end
end)


Mouse.KeyDown:connect(function(k)
    k = k:lower()
    if k == "e" then
        if not Enabled then return end
        local Target = Mouse.Target
        if not Target then return end
        Target = Target.Parent
        if not Target then return end
        local Mag = 9

        if Target.Name == "Door" or Target.Name == "Examine" then
            Mag = (Player.Character.Torso.Position - Target.Main.Position).magnitude
        end

        local N = Target.Parent.Name
        if Mag <= 8 then
            if N == "Examine" then
                Target = Target.Parent
                if not Target.Examinable.Value then return end

                Enabled = false
                Camera.CameraType = "Scriptable"
                Camera.CameraSubject = Target
                Camera.CoordinateFrame = Target.Cam.CFrame
                Camera.Focus = Target.Body.Torso.CFrame
                Player.Character.Humanoid.WalkSpeed = 0
                T.Text = Target.Text.Value

                for i,v in pairs(Target.Items:GetChildren()) do
                    local C = game.ReplicatedStorage:FindFirstChild(v.Value)

                    if C ~= nil then
                        C = C:clone()
                        local C1 = C:clone()
                        C.Parent = Player.StarterGear
                        C1.Parent = Player.Backpack

                        for k, l in pairs(C:children()) do
                            if l.ClassName == "Part" then
                                l.Anchored = false
                            end
                        end

                        for k, l in pairs(C1:children()) do
                            if l.ClassName == "Part" then
                                l.Anchored = false
                            end
                        end
                    end

                    v.Parent = nil
                end

                Target.Rem.Parent = nil
                wait(2)
                Camera.CameraType = "Custom"
                Camera.CameraSubject = Player.Character.Humanoid
                Player.Character.Humanoid.WalkSpeed = 12
                T.Text = ""
                Target.Examinable.Value = false
                Enabled = true
            elseif Target.Name == "Door" then
                if Target.Lock.Value == true then
                    Enabled = false
                    T.Text = "This door is locked! Find a key to open it."
                    wait(2)
                    Enabled = true
                    return
                end

                if Target.Open.Value == true then return end
                Target.Open.Value = true

                for i = 1,78 do
                    wait()
                    Target.Main.CFrame = Target.CFrame * CFrame.new(0, -0.1, 0)
                end

                wait(2)

                for i = 1,78 do
                    wait()
                    Target.Main.CFrame = Target.CFrame * CFrame.new(0, 0.1, 0)
                end

                wait(1)
                Target.Open.Value = false
            end
        end
    elseif k == "c" then
        if Crouching == false then
            --_G.Crouch(true)
            Crouching = true
        elseif Crouching == true then
            --_G.Crouch(false)
            Crouching = false
        end
    end
end)

Mouse.Button1Down:connect(function()
    local Target = Mouse.Target
    if not Target then return end
    Target = Target.Parent.Parent
    if not Target then return end

    if Player.Character:FindFirstChild("Key") then
        if Target.Name == "Door" then
            if Target.Lock.Value then
                if Player.Character.Key.Handle.BrickColor == Target.DoorColor.Value then
                    Enabled = false
                    T.Text = "Successfully opened door!"
                    Target.Lock.Value = false
                    Player.Character.Key.Parent = nil
                    wait(1.5)
                    Enabled = true
                    T.Text = ""
                elseif Player.Character.Key.Handle.BrickColor ~= Target.DoorColor.Value then
                    Enabled = false
                    T.Text = "This key does not fit the keyhole!"
                    wait(1.5)
                    Enabled = true
                    T.Text = ""
                end
            end
        end
    end
end)

Is it possible that it's not the script, and just your setup of the hierarchy? (That a value is false when it should be true by default, or vice versa)

It looks like the code SHOULD work. The best way to debug is to add print("Test #[NUMBER]") or something like that, to see where it doesn't go when it should.

Ad

Answer this question