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
7 years ago

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

01Player = game.Players.LocalPlayer
02Mouse = Player:GetMouse()
03gui = script.Parent
04Button = gui.Button
05Open = false
06 
07script.Parent.Activated:connect(function()
08local dinnertime = script.Parent.Parent.Humanoid:LoadAnimation(script.eat)
09dinnertime:Play()
10end)
11 
12function PressE(key)
13    if (key == "E")
14        button.Visible = true
15        Open = true
View all 22 lines...

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 7 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:

1gui = script.Parent

When it should read:

1gui = 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:

1script.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:

1local 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:

1local 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 7 years ago
Edited 7 years ago

Try this man

This my script

01local player = game.Players.LocalPlayer
02local Mouse = player:GetMouse()
03 
04Mouse.KeyDown:connect(function(key)
05    if key == "c" then
06        if script.Parent.Enabled == false then -- My Gui
07            script.Parent.Enabled = true
08        elseif
09            script.Parent.Enabled == true then
10            script.Parent.Enabled = false
11        end
12    end
13end)

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

Answer this question