Scripts wont work after they get enabled?

  1. What do you want to achieve? I want to make it so that when a flashlight is (fake) equipped using a proximity prompt, two scripts for a F to Flashlight type system to enable

  2. What is the issue? When the proximity prompt is triggered and the scripts enabled, the code in the scripts wont work? I tried them without having them enabled by script and they worked?

  3. What solutions have you tried so far? I haven’t tried any yet because i literally dont have any idea why this happened

This is the script that enables the flashlight script:

and these are the flashlight scripts:
image


1 Like

Have you tried changing the lines 7 to 9 on the local script that reads inputs to

if input.KeyCode == keyPress then

For UserInputService, I think you need a second parameter called “gameprocessed”. I’m pretty sure this just checks if the game processed your input. For your local script, the UIS function should be set up like this:

UserInputService.InputBegan:Connect(function(input,gameprocess)
	if not gameprocess then
		if input.KeyCode == Enum.KeyCode.F then
			--code here
		end
	end
end)
1 Like

It doesn’t work, maybe i implemented it wrong tho?

image

Your code looks correct, can you check output to see if any errors show up? If there are any, list the errors. If there aren’t any, check your scripts for any typos forgot to type in a line of code.

For the flashlight script, I’m assuming you want the player to pick up some type of object that unlocks a flashlight which can be activated by pressing F?

there are no errors. Yes its a flashlight script and when a equip prox prompt is triggered i want the flashlight scripts to enable because its 2 different systems. This is because im making a different custom made inventory. so the flashlight cant be a tool with a flashlight system in it. The flashlight system is a free model tho so if you wanna check the original code or something its called “Press F for Flashlight” by Tomatothebob

I’m not at my PC but I can try writing a flashlight system that works when I get back. In the meantime you can try using “print(message)” to see if code runs. Basically put “print(message)” where the you want your other functions to run. If you see the message you put in the print then the code should run. If you don’t see the message you put in “print” then that means it didn’t run.

yeah i tried that before with prints, the scripts arent running when they get enabled (flashlight scripts)

as in getting enabled by scripts* they work if i enable manually in studio

Change Game.startergui.flashlight gui to player.playergui.flashlight
change all of the startergui vars to player.playergui.(path)

im not really sure what exactly would this do??

It uses the clients playergui which is more flexible I believe, you can turn scripts on and off with playergui and you can move them

flashlight is a script not a gui tho

Maybe what you can do is have a variable to keep track whether or not you have collected the flashlight. When you collect the flashlight, you can set the variable to true to indicate that you have collected it. You can make the code you have currently only run when the variable is true. That way you can keep the scripts on all of the time and you can only activate the flashlight once you unlocked it.

1 Like

Yes but it’s in startergui. Playergui can contain scripts too but if you don’t wanna try what I’m suggesting then you don’t have to

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.