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

Question about smoke? (This is my FIRST script, so PLEASE DO NOT Judge me)

Asked by 11 years ago

Hello.

How do I make a part where you press "UpArrowKey", and then smoke starts to come out. But when you press "DownArrowKey", no smoke comes out.

(This is my First "Script", So PLEASE do not judge on how bad this is).

function Hotkey "UpArrowKey" then game.workspace.JT8D.SmokePart.Smoke.enabled = "true" then Hotkey"DownArrowKey" then game.workspace.JT8D.SmokePart.Smoke.enabled = "false"

end

0
You can't use quotes in a boolean. (Also, you can refer to the player as game.Players.LocalPlayer) AlphaSpawn 4 — 6y

3 answers

Log in to vote
0
Answered by
Maxomega3 106
11 years ago

A couple of things: *Workspace and Enabled are always capitalized. *You can't have then following a function *You can't assign the WASD/Arrow Keys without some complex coding. Try q and e instead. *For a boolean value (true/false value), you can't put it in quotes or else it becomes a string (line of text).

In order to call a function, you must use a .KeyDown event of Mouse. Mouse is only to be used in a local script.

01player = game.Players.LocalPlayer -- That's the person which has the script in their PlayerGui, Backpack, or Character
02mouse = player:GetMouse () -- gets the mouse
03 
04function KeyDown (key) -- a function is called whenever a player hits a key on the keyboard
05    if key:lower () == "q" then -- :lower () is just all lowercase. This means it will trigger if the q is capitalized
06    game.Workspace.JT8D.SmokePart.Smoke.Enabled = true -- There's your line revised.
07    end -- closes if statement
08end -- closes function
09 
10mouse.KeyDown:connect (KeyDown) -- connection line for the function to know when to trigger

Now try to make one with the e key and disabling the smoke!

Ad
Log in to vote
0
Answered by
aalok 20
11 years ago

Hi! My name is TheEliteDonphan. I'll help you fix your script.

First of all, you need to create access to the players mouse and keyboard (GetMouse)

1local keyb = game.Players.JT8D:GetMouse()

And then you want to define your player.

1local plr = game.Players.JT8D
2local keyb = plr:GetMouse()

Then you use this predefined string "Mouse.KeyDown" and create a function in it (replaces :connect() at the end)

1Mouse.KeyDown:connect(function(key)
2 
3end)

And then you use the hex escape to construct the special up arrow key

1Mouse.KeyDown:connect(function(key)
2    if key == "/x11" then
3    --more code
4end)

Then add the smoke code to the up arrow key "if statement" + add the down key hex

1Mouse.KeyDown:connect(function(key)
2    if key == "/x11" then
3        local char = game.Workspace.JT8D.SmokePart.Smoke
4        char.Enabled=true
5    elseif key == "/x12" and game.Workspace.JT8D.SmokePart.Smoke.Enabled == true then -- down arrow key hex and error handler
6        local char = game.Workspace.JT8DSmokePart.Smoke
7        char.Enabled=false
8end
9end)

Source: wiki.roblox.com

Log in to vote
0
Answered by 11 years ago

I do similar stuff using the A and D keys to sound horns on train locomotives. It's done from the vehicle seat. If you use a vehicle seat, you can use the throttle and steering to your advantage VERY easily, as long as its unanchored, and it will still work if it is welded to the ground. Let's say I want to sound a horn located inside the seat, when either A or D are held. (or LeftArrowKey or RightArrow Key) A and D change the steering values to -1 and 1. When neither are pressed the steer value is 0. So, when the value is 1 or -1, the horn will start sounding. When you release the key and it turns to 0, it stops sounding. Here's the script I use, on which you can make a few changes to work with your smoke:

1while true do
1wait(.0000000001)
1if script.Parent.Steer == 1 or script.Parent.Steer == -1 then
1script.Parent.Horn:Play()
1elseif script.Parent.Steer == 0 then
1script.Parent.Horn:Stop()

end ~~~~~~~~~~~~~~~~~ Just change the script.Parent.Horn:Play() to enable the smoke in a certain part, and script.Parent.Horn:Stop() to disable the smoke. Then as I hold down A, D, LeftArrowKey, or RightArrowKey, the smoke will do its thing. When none of those 4 are pressed, the smoke will stop. Just like my horn for my trains. If you would like me to make the smoker for you, just tell me either here, or on ROBLOX, however the best way to contact me is to shoot me an email at DieselElevators@Gmail.com and just tell me it's you. I'll be more than happy to make it for you.

Answer this question