How to hide trigger interaction label for local player?

When a player interacts with a trigger I've set up, it opens a UI and everything works perfect EXCEPT the interaction label still shows on top of my UI.

Is there a way to hide the interaction label for the local player only, and not change it for all players? I tried setting player.isVisibleToSelf to false which still leaves the label floating there. I also see that the interaction label can be changed with script, but doesn't this change it for everyone? I only want it to hide for the people who have the UI open.

Check my answer for a full example.

Hi,

You can modify the isInteractable property of the trigger. Setting it to false will turn off the label, and setting it to true will turn it on.

To make sure that this only gets applied to the local player, you want to compare the local player with the player in the trigger.

For example, take the code below, it will compare the obj parameter against the local_player variable, and only alter the state of the isInteractable property for that local player.

local local_player = Game.GetLocalPlayer()

local function on_enter(the_trigger, obj)
	if(Object.IsValid(obj) and obj:IsA("Player") and obj == local_player) then
		the_trigger.isInteractable = false
	end
end

local function on_exit(the_trigger, obj)
	if(Object.IsValid(obj) and obj:IsA("Player") and obj == local_player) then
		the_trigger.isInteractable = true
	end
end

trigger.endOverlapEvent:Connect(on_enter)
trigger.beginOverlapEvent:Connect(on_exit)

Another way to do it, is when the player triggers the interactedEvent, then disable the label.

local function on_interacted(the_trigger,  obj)
	if(Object.IsValid(obj) and obj:IsA("Player") and obj == local_player) then
		the_trigger.isInteractable = true
	end
end

trigger.interactedEvent:Connect(on_interacted)

When the UI is closed, then you can enable the interaction label again.

https://docs.coregames.com/api/trigger/


Here is a better example for you to try.

Below is the full script, or if you prefer to see a working example, save the image at the end, and drag it into your project (it's an image with an embedded template).

local trigger = script:GetCustomProperty("trigger"):WaitForObject()
local shop_ui = script:GetCustomProperty("shop_ui"):WaitForObject()
local close_button = script:GetCustomProperty("close_button"):WaitForObject()

local local_player = Game.GetLocalPlayer()
local in_trigger = false

local function close_ui()
	shop_ui.visibility = Visibility.FORCE_OFF

	if(in_trigger) then
		trigger.isInteractable = true
	else
		trigger.isInteractable = false
	end

	UI.SetCursorVisible(false)
	UI.SetCanCursorInteractWithUI(false)
end

local function on_interacted(t, obj)
	if(in_trigger and Object.IsValid(obj) and obj:IsA("Player") and obj == local_player) then
		shop_ui.visibility = Visibility.FORCE_ON
		trigger.isInteractable = false

		UI.SetCursorVisible(true)
		UI.SetCanCursorInteractWithUI(true)
	end
end

local function on_exit(t, obj)
	if(Object.IsValid(obj) and obj:IsA("Player") and obj == local_player) then
		in_trigger = false
		close_ui()
	end
end

local function on_enter(t, obj)
	if(Object.IsValid(obj) and obj:IsA("Player") and obj == local_player) then
		trigger.isInteractable = true
		in_trigger = true
	end
end

close_button.clickedEvent:Connect(close_ui)

trigger.interactedEvent:Connect(on_interacted)
trigger.endOverlapEvent:Connect(on_exit)
trigger.beginOverlapEvent:Connect(on_enter)

Ohh, thank you!! I think I'm missing some fundamental knowledge here so it's nice to get a bit of script from someone who knows what they're doing. I'll try incorporating this concept.

Been trying to get something like this working for a bit now and I'm having a terrible time with the network contexts. The "isInteractable" property can only be changed from a server-side script while Game.GetLocalPlayer() can only be used in the client context.

I was trying to set up the conditional statement to check for the local player on the client context, then broadcast to the server-side script where the isInteractable property would be changed, but this changes the label for all players in the game and not just the local player.

Very confusing!

I think I'm just gonna go back to the drawing board and try another method. I didn't think hiding such a small silly little text box would be so hard...