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

Major GUI Issues? (Too many to list in the title, they're listed at the start of the body)

Asked by
RoboFrog 400 Moderation Voter
9 years ago

Alright, I've been working on a pickaxe script for a while, and everything was working nicely until today. the main portion of the script functions perfectly and without any error. The problem arises with a script to display the name of the ore, which gives me so many errors. I have it marked at the bottom with "-- Code Start" or something like that.

The ore display isn't working correctly (not going visible) and to my knowledge it isn't following the mouse, either. The color doesn't seem to be changing properly, and I can't rightfully say for the text, either.

This is all also in a local script.

The script is having these issues:

  • It's not moving properly with the mouse.
  • It isn't shutting off or waiting properly
  • It's activating too frequently
  • It's not distinguishing model names correctly (activating when mousing over stuff it shouldn't
  • And more that I can't really think of.

I'll post most of the code, since I've got a lot of variables that are created in portions that aren't created globally or in the code in question --

local deposits = {"Stone", "Copper", "Tin", "Silver", "Gold", "Platinum"} -- X are the deposits mineable.
local reload = .5 -- X is time between swings
local picksize = 7 -- X is mining distance

local perchancest = 60 -- X% chance of mining stone.
local perchanceco = 50 -- X% chance of mining copper.
local perchanceti = 50 -- X% chance of mining tin.
local perchancesi = 40 -- X% chance of mining silver.
local perchancego = 30 -- X% chance of mining gold.
local perchancepl = 30 -- X% chance of mining platinum.

local light = game.Lighting.globaltyc
local ipath = game.Workspace.Tycoon.Tycoon.InvInt -- Anything inside this is an integer value.
local gui3true = game.Workspace.Tycoon.Tycoon.gui3true.Value -- A bool value
local bpath = game.Workspace.Tycoon.Tycoon.Binding.Value -- An integer value
local hit = (tostring(game.Players:findFirstChild("humanoid")))
local debounce = true
local on = script.Parent.Name
local mouse = game.Players.LocalPlayer:GetMouse()

function onActivated(mouse)

    if debounce == false then return end
    debounce = false

    if not mouse then return end

    local targ = mouse.Target

    slash()

    if targ ~= nil then

        if targ.Parent ~= nil then

            if (targ.Position - script.Parent.Parent.Head.Position).magnitude < picksize then

                local human = targ.Parent:findFirstChild("Humanoid")

                if human ~= nil then
                    print("Found human")

                    human:TakeDamage(10+math.random(30))

                else

                    local action = false
                    for i = 1, #deposits do
                        if targ.Parent.Name == deposits[i] then
                            print("Target is "..targ.Parent.Name.."!")
                            action = true
                            break
                        end
                    end

                    if action == true then

                        if targ.Parent.Name == "Stone" then
                        stone1()

                        elseif targ.Parent.Name == "Copper" then
                        copper1() -- function cut for space (about the same as stone1())

                        elseif targ.Parent.Name == "Tin" then
                        tin1()-- function cut for space

                        elseif targ.Parent.Name == "Silver" then
                        silver1()-- function cut for space

                        elseif targ.Parent.Name == "Gold" then
                        gold1()-- function cut for space

                        elseif targ.Parent.Name == "Platinum" then
                        platinum1()-- function cut for space

                        else print("No ore found")
                        end

                end

            end

        end

    end

    print("Reloading!")

    wait(reload)

    debounce = true
    script.Parent.Name = on
    end
    end

function stone1()
    local chance = math.random(100)
    if chance <= perchancest then
        if math.random(100) <= bpath then
        ipath.Stone.Value = ipath.Stone.Value + 1
        local gui = game.Lighting.Gui4:Clone()
        gui.Parent = game.Players.LocalPlayer.PlayerGui
        gui.Text.Text = (mouse.Target.Parent.Name.." ore added!")
        gui.Text.BackgroundColor3 = Color3.new(0, 1, 0)
        mouse.Target:Destroy()
        else
        local gui = game.Lighting.Gui4:Clone()
        gui.Parent = game.Players.LocalPlayer.PlayerGui
        gui.Text.Text = "The ore was broken..."
        gui.Text.BackgroundColor3 = Color3.new(1, 0, 0) 
        mouse.Target:Destroy()  
        end
            else
            local gui = game.Lighting.Gui4:Clone()
            gui.Parent = game.Players.LocalPlayer.PlayerGui
            gui.Text.Text = "Failed to mine..."
            gui.Text.BackgroundColor3 = Color3.new(1, 0, 0)
            wait(1)
    end
end

function slash()
    local anim = Instance.new("StringValue")
    anim.Name = "toolanim"
    anim.Value = "Slash"
    anim.Parent = script.Parent
end

function onEquipped(mouse)
    script.Parent.Activated:connect(function() onActivated(mouse) end)
    print(mouse)
    local oredisplay = false    

-- CODE IN QUESTION START ----------------------------------------------------------------

    if oredisplay == false then
        print("Oredisp Initiated!")
        oredisplay = true
        local gui = game.Lighting.Gui3:Clone()
        gui.Parent = game.Players.LocalPlayer.PlayerGui
    end
end

mouse.Move:connect(function()
    local gui = game.Lighting.Gui3
    local gui3 = game.Players.LocalPlayer.PlayerGui.Gui3
    gui3.Text.Position = UDim2.new(mouse.X, mouse.Y)
    if mouse.Target.Parent.Name == "Stone" or "Copper" or "Tin" or "Silver" or "Gold" or "Platinum" then
    game.Players.LocalPlayer.PlayerGui.Gui3.Text.Visible = true 
    gui.Text.Text = (tostring(mouse.Target.Parent.Name))
    --print("Target is an ore")
    if gui3true == true then print("gui3true is true!") wait(1) end
    if gui3true == false then print ("gui3true is false!")
    if mouse.Target.Parent.Name == "Stone" then
        gui3.Text.Text = "Stone Ore"
        gui3.Text.BackgroundColor3 = Color3.new(158, 158, 158)
        gui3true = true
        wait(1)
        gui3true = false
        gui3.Text.Visible = false
    elseif mouse.Target.Parent.Name == "Copper" then
        gui3.Text.Text = "Copper Ore"
        gui3.Text.BackgroundColor3 = Color3.new(209, 160, 0)
        gui3true = true
        wait(1)
        gui3true = false
        gui3.Text.Visible = false
    elseif mouse.Target.Parent.Name == "Tin" then
        gui3.Text.Text = "Tin Ore"
        gui3.Text.BackgroundColor3 = Color3.new(196, 196, 161)
        gui3true = true
        wait(1)
        gui3true = false
        gui3.Text.Visible = false
    elseif mouse.Target.Parent.Name == "Silver" then
        gui3.Text.Text = "Silver Ore"
        gui3.Text.BackgroundColor3 = Color3.new(196, 196, 196)
        gui3true = true
        wait(1)
        gui3true = false
        gui3.Text.Visible = false
    elseif mouse.Target.Parent.Name == "Gold" then
        gui3.Text.Text = "Gold Ore"
        gui3.Text.BackgroundColor3 = Color3.new(235, 235, 52)
        gui3true = true
        wait(1)
        gui3true = false
        gui3.Text.Visible = false
    elseif mouse.Target.Parent.Name == "Platinum" then
        gui3.Text.Text = "Platinum Ore"
        gui3.Text.BackgroundColor3 = Color3.new(237, 237, 237)
        gui3true = true
        wait(1)
        gui3true = false
        gui3.Text.Visible = false
    else print("Wrong target!")
        game.Players.LocalPlayer.PlayerGui.Gui3.Text.Visible = false 
    end
    end
    end
end)

-- CODE IN QUESTION END ---------------------------------------------

script.Parent.Equipped:connect(onEquipped)

Now, for the important part -- the output errors and statements:

  • Whenever I remove the -- in front of "print("Target is an ore")", it prints this constantly whenever my mouse moves over something that's not listed as an ore (baseplate, shops, et cetera):

    • Target is an ore
    • gui3true is false!
    • Wrong target!
  • Whenever I have that removed still and move it over an ore, it repeats this constantly:

    • Target is an ore
    • gui3true is true!

If you need any other scenarios for output, please let me know. I'm sure I'm forgetting some that are important.

(As a bonus, if it can be figured out why when I'm lagging badly and click the baseplate, it sometimes "mines" it, I'd love some info on that, since I can't tell if this is a coding issue or a flaw in the ROBLOX engine)

Like always, thank you for reading, and any help possible is greatly appreciated!

1
I think including the whole script is a bit intimidating for people who want to answer. Tortelloni 315 — 9y
0
I completely agree. However, that's still not even the entire script. I wanted to include anything that had relation to the part that was an issue, so variables and such weren't too confusing. RoboFrog 400 — 9y

Answer this question