ProximityPrompt Toggle On/Off & Action Text Help

So recently I’ve been trying to make things like Torches, or campfires using Proximity Prompt and I’ve been having the issue of going the round about of making it so when a user triggers the proximity prompt once it will either turn it on then turn it off or the other way around.

But at the same time I’m wanting it to change from “Light fire” to “Extinguish Fire”.

I looked at the recent “Proximity Prompt” tutorials, and everything having to do with changing the UI, and I still couldn’t find the simple way of changing the “Action Text” which is the property that will display “Light Fire” or “Extinguish Fire”.

Here is my previous source code

local smoke = script.Parent.Parent.Part.smoke
local light = script.Parent.Parent.Part.PointLight
local particle = script.Parent.Parent.Part.ParticleEmitter
local sound = script.Parent.Parent.Part.Sound


button.ProximityPrompt.Triggered:Connect(function(player)
	print("The user lit me!")
	smoke.Enabled = true
	light.Enabled = true
	particle.Enabled = true
	sound.Playing = true
	
	wait(200)
	
	print("I just died out")
	smoke.Enabled = false
	light.Enabled = false
	particle.Enabled = false
	sound.Playing = false
	
end)

This source code is just turning all the particles on, and then after a bit they will automatically turn off. Please let me know if you have any ideas!
1 Like
local toggle = true
ProximityPrompt.Triggered:Connect(function(player)
	toggle = not toggle
	ProximityPrompt.ActionText = toggle and "State1" or "State2"
end)

Hope this helped!

1 Like
local smoke = script.Parent.Parent.Part.smoke
local light = script.Parent.Parent.Part.PointLight
local particle = script.Parent.Parent.Part.ParticleEmitter
local sound = script.Parent.Parent.Part.Sound
local toggle = true

button.ProximityPrompt.Triggered:Connect(function(player)
	print("The user lit me!")
	smoke.Enabled = true
	light.Enabled = true
	particle.Enabled = true
	sound.Playing = true
	
	toggle = not toggle
	button.ProximityPrompt.ObjectText = toggle and "Light Me" or "Exstinguish Me"
	
	-- TO DO (after first toggle or from on) to (off)
	smoke.Enabled = false
	light.Enabled = false
	particle.Enabled = false
	sound.Playing = false
	
end)

Could you possibly help me out with the last part? I put a TO DO comment by it. Im just super confused on the after you toggle it from on how can I have it turn off?

would I have to make two different functions one for State 1 = on or state 2 = false?

Please let me know. But the ObjectText works perfectly so thankyou!

1 Like

When toggle is true, you extinguished the fire, and thus you prompt "Light me". Therefore all you need to do is to check if toggle is currently false:

button.ProximityPrompt.Triggered:Connect(function(player)
	toggle = not toggle
	button.ProximityPrompt.ObjectText = toggle and "Light Me" or "Exstinguish Me"

	if toggle then -- Extinguish the fire
		smoke.Enabled = false
		light.Enabled = false
		particle.Enabled = false
		sound.Playing = false
	else -- Light the fire
		print("The user lit me!")
		smoke.Enabled = true
		light.Enabled = true
		particle.Enabled = true
		sound.Playing = true
	end
end)

It’s kinda confusing, but I hope you can get the hang of it XD

If the result is the opposite of what you wanted, you could always do if not toggle then, or just move the code around.

2 Likes