Change proximity prompt text when toggled

How do I change Proximity Prompt’s ActionText when it’s toggled?

I’m going by the assumption that you understand functions? If not, feel free to reply stating so and I can explain!

Otherwise, what I’d do (assuming you are changing between two sets of text) is I’d have a variable with a number or value assigned. Can be anything. In this instance, let’s say your variable is equal to 1.

Next, when the prompt is triggered, we check what the variable is equal to. If it is equal to 1, set the actiontext to “text1” and change the variable to a different value e.g. 2. If the variable is not equal to 1, change the actiontext to “text2” and change the variable back to 1.

The gist of it would be connecting to the toggled event.

It would probably be done like so:

local p = Instance.new("ProximityPrompt")
p.Triggered:Connect(function(playerWhoTriggered: Player) 
	p.ActionText = "some action text"
	p.ObjectText = "the object text"	
end)

I don’t know what you’re saying. But the proximity prompt’s text should ALREADY be “Text1” and when the player toggles it, IT CHANGES TO “TEXT2” and when the PLAYER TOGGLES IT AGAIN it changes back to “Text1” and so on. I’m making a lightswitch toggle, It should ALREADY say “Turn On” and when the player toggles it, it changes to “Turn Off” and when the player toggles it AGAIN it changes BACK to “Turn On” AND SO ON. I hope you understand what i’m trying to say.

Assuming you’re putting the script inside of the ProximityPrompt object itself:

local pp = script.Parent
local toggle = 0
pp.Triggered:Connect(function(playerWhoTriggered: Player) 
	toggle += 1
	if toggle == 1 then
		-- your turn ON light code below
		-- ----------------------------
		
		-- ----------------------------
		
		-- since it's on, change the prompt text accordingly
		pp.ActionText = "Turn off the light"
	else
		toggle = 0
		-- your turn OFF light code below
		-- ----------------------------

		-- ----------------------------
		
		-- since it's off, change the prompt text accordingly
		pp.ActionText = "Turn on the light"
	end
end)

Hope that helps.

1 Like

Modified Version of your code.

local pp = script.Parent
local toggle = 0

pp.Triggered:Connect(function(playerWhoTriggered: Player) 
	if toggle == 0 then
        toggle = 1
		-- your turn ON light code below
		-- ----------------------------
		
		-- ----------------------------
		
		-- since it's on, change the prompt text accordingly
		pp.ActionText = "Turn off the light"
	elseif toggle == 1 then
		toggle = 0
		-- your turn OFF light code below
		-- ----------------------------

		-- ----------------------------
		
		-- since it's off, change the prompt text accordingly
		pp.ActionText = "Turn on the light"
	end
end)

Adding it so the script adds +1 to the toggle variable is kind of buggy because people can spam it and add alot more than 1.

1 Like

Not true because if it’s anything other than 1, it gets set back to 0, but yours is a bit more readable to the eye so that’s a benefit.

thanks, @elmlingg 's script works too

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