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)