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

How do you make a clickable Billboard GUI and a KeyDown Event?

Asked by
dog6779 25
6 years ago

So I made this script. But it seem not to work.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
gui = script.Parent
Button = gui.Button
Open = false

script.Parent.Activated:connect(function()
local dinnertime = script.Parent.Parent.Humanoid:LoadAnimation(script.eat)
dinnertime:Play()
end)

function PressE(key)
    if (key == "E")
        button.Visible = true
        Open = true
    elseif (Open == true) then
        button.Visible = false
        Open = false
        end
    end
end
Mouse.KeyDown:connect(PressE)

What I trying to do here is that I want the player that can click and to key event by pressing E. But when I saw something in the script the word button is seem to be red underline. And I trying to make like the player to press the E and get to click then after that it plays a animation WITH the TOOL.

I don't know how it's not working.

And here are some pictures to know what I am doing. And I am also doing it in a billboard way.

And I trying to make where the person also walk to it. It appears but when the player walk away it disappear.

https://gyazo.com/6509e48c4204923a7c4b78cb1c75ca45 https://gyazo.com/df935ee2611f221c572f256fe5e2f515 https://gyazo.com/c5bf5000f2acaef03f799029c6f81d2c

2 answers

Log in to vote
1
Answered by 6 years ago

Your script presents the following errors:

First of all, a Local Script won't run from where you've located it. According to the roblox wiki: " A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  1. A Player's Backpack, such as a child of a Tool

  2. A Player's Character model

  3. A Player's PlayerGui

  4. A Player's PlayerScripts

  5. The ReplicatedFirst service "

On the third line you are wrongly defining your "gui" variable, it reads:

gui = script.Parent

When it should read:

gui = script.Parent.Parent

Since your script's Parent is the Button and the Button's Parent is the gui.

Also, on the seventh line which reads:

script.Parent.Activated:connect(function()

script.Parent is refering to the Button; the .Activated event won't trigger from your Button but it will from the tool (which is what you intended I believe). Also on the next line:

local dinnertime = script.Parent.Parent.Humanoid:LoadAnimation(script.eat)

If you wish to reference the Player's Humanoid, that's not the correct path. It should read something like:

local dinnertime = Player.Character.Humanoid:LoadAnimation(script.eat)

Overall, I would advise you not to put your tool as a child of your gui, but rather the opposite; your tool as the parent of your gui and script. After that, redifine your variables accordingly.

Best regards!

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Try this man

This my script

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()

Mouse.KeyDown:connect(function(key)
    if key == "c" then
        if script.Parent.Enabled == false then -- My Gui
            script.Parent.Enabled = true
        elseif
            script.Parent.Enabled == true then
            script.Parent.Enabled = false
        end
    end
end)

Change Enabled. to .visible in line 6 if you want frame

Answer this question