Updating a script while game is running

Hi everyone. I’m trying to make my ski tool so when you tap on a key on your keyboard it ‘freezes’ the user who’s using the tool. By that, I mean stopping the movement of the user. I’ve found this line regulates this, and when I section it out as a comment (by doing --), it does what I would like it to do. However, I’m having trouble actually making the code not read it (skip past it) depending on if a key has been pressed, let’s say for this example, f on the keyboard. I’ve tried using a if statement and tried elif and else, however the tool just breaks when I do that. The only thing that works is two dashes to comment it out.

So I was wondering if there was a way to update the code so it adds and removes the two dashes (which section that line for commenting) when the f key has been pressed. I’m 70% sure that this isn’t possible, so could anyone tell me on what to do? The line + the code is shown below:

(I’ve searched on here, but there are no threads that help me)

Could you provide the full script as it’s very hard for us to assist you with just one line to work with?

The full script is extremely long (495 lines in total), so I’m not sure it would help you. This is the section the code is in though:

Are you sure the if statment breaks it? Didn’t you try to just

if UserInputService:IsKeyDown(Enum.KeyCode.<the key you want>) then

And also from what I know there is no way of editing a script not manually, something you can do is have a seperate that’s enabled or would only run if it recieves a signal (embedded events/ fuctions) but that’s kind of really unneficient and hacky.

Okay, i’ve done it. It looks like this:


Not sure why there its showing that error though

Well you didn’t define UserInputService yet! Always pay attention to these little mistakes

You have to define it using game:GetService(),

local UserInputService = game:GetService("UserInputService")

Cheers, forgot to do that. It still breaks even with your code inserted. Forgot to switch my character to R6 :rofl: The tool isn’t compatible with R15 which is what I was using), thank you so much!!! :grin:

1 Like

Perhaps the if statment only checked once, because if statments don’t keep on checking, meaning they only check when when the game starts.
For example, we have an if statment that checks if a value is equal to true, as soon as the game starts that value is false, but after 5 minutes it’s changed to true, but the if statment wouldn’t pass when it changed to true, because it already checked at the game’s start and it wasn’t false so it went on.

1 Like