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 10 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 — 5y

3 answers

Log in to vote
0
Answered by
Maxomega3 106
10 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.

player = game.Players.LocalPlayer -- That's the person which has the script in their PlayerGui, Backpack, or Character
mouse = player:GetMouse () -- gets the mouse

function KeyDown (key) -- a function is called whenever a player hits a key on the keyboard
    if key:lower () == "q" then -- :lower () is just all lowercase. This means it will trigger if the q is capitalized
    game.Workspace.JT8D.SmokePart.Smoke.Enabled = true -- There's your line revised.
    end -- closes if statement
end -- closes function

mouse.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
10 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)


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

And then you want to define your player.

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

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


Mouse.KeyDown:connect(function(key) end)

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

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

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

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

Source: wiki.roblox.com

Log in to vote
0
Answered by 10 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:

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

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 [email protected] and just tell me it's you. I'll be more than happy to make it for you.

Answer this question