So I made this script. But it seem not to work.
01 | Player = game.Players.LocalPlayer |
02 | Mouse = Player:GetMouse() |
03 | gui = script.Parent |
04 | Button = gui.Button |
05 | Open = false |
06 |
07 | script.Parent.Activated:connect( function () |
08 | local dinnertime = script.Parent.Parent.Humanoid:LoadAnimation(script.eat) |
09 | dinnertime:Play() |
10 | end ) |
11 |
12 | function PressE(key) |
13 | if (key = = "E" ) |
14 | button.Visible = true |
15 | Open = true |
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
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:
A Player's Backpack, such as a child of a Tool
A Player's Character model
A Player's PlayerGui
A Player's PlayerScripts
The ReplicatedFirst service "
On the third line you are wrongly defining your "gui" variable, it reads:
1 | gui = script.Parent |
When it should read:
1 | 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:
1 | 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:
1 | 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:
1 | 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!
Try this man
This my script
01 | local player = game.Players.LocalPlayer |
02 | local Mouse = player:GetMouse() |
03 |
04 | Mouse.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 |
13 | end ) |
Change Enabled. to .visible in line 6 if you want frame