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

how would i Make a GUI appear when holding a tool? + how to make GUI change numbers?

Asked by 4 years ago

I am making a force field tool and I am trying to make some things

Alright, this really is a two question question, but here's the first question I have. I made this little script here that in theory should work, but it doesn't.

local player = game.Players.LocalPlayer --dont change plz
local gui = player.PlayerGui.GUIMAN --the gui you would like to show (rename MyScreenGUI to your gui name in startergui)

gui.Parent = nil

script.Parent.Equipped:connect(function(mouse)
    gui.Parent = player.PlayerGui
end)

script.Parent.Unequipped:connect(function(mouse)
    gui.Parent = nil
end)

(I put those little reminders to remind myself because I am very forgetful and I do this to all my scripts)

So then I proceed to put the GUI inside of the tool like this: https://gyazo.com/6a6ba116de2d101e4a931e386af33747

The name of my GUI is GUIMAN by the way So now when I hold the tool the GUI does not appear at all? Why is this?

Even when I move the gui to starter gui it doesn't change anything, this is very strange. Do I need to make the script a LocalScript? I tried doing that as well and it did not change anything, so I changed it back to a regular script

Another thing I would like is for the GUI to change its text according to the delay of the force field

This is the script I have so far

Tool = script.Parent

local field = nil

function shieldsUp()

    if (field == nil) then
        Tool.Handle.Boing:play()

        local vCharacter = Tool.Parent

        Tool.Handle.BrickColor = BrickColor.new(24) -- yellow when the forcefield is active 

        field = Instance.new("ForceField")
        field.Parent = vCharacter

    end

end

function shieldsDown()
    if (field ~= nil) then
        field.Parent = nil
        field = nil
        Tool.Handle.BrickColor = BrickColor.new(104) -- purple change color when the shield on cooldown
    end
end


Tool.Enabled = true
function onActivated()

    if not Tool.Enabled then
        return
    end

    Tool.Enabled = false

    shieldsUp()

    wait(10)--ten second force feild

    shieldsDown()

    wait(5)--5 second cooldown

    Tool.Enabled = true
end


script.Parent.Activated:connect(onActivated)
Tool.Unequipped:connect(shieldsDown)

So I want the GUI's text to change according to the delay. So I was thinking about something like this

    shieldsDown()

    local cooldown = wait(5)--5 second cooldown

    Tool.Enabled = true
end

making a variable or whatever it is to the delay and then taking that and then putting a localscript into the gui and making it like this

while true do
script.Parent.Text = cooldown

So If I didn't make clear yet here is what the setup of the scripts and placement looks like: https://gyazo.com/f9c470ff722ca358831e4c0f89d760e4

lastly: to make clear, the force field is working but the GUI stuff isn't working

Answer this question