i have problem. A proximity promt which opens ui but to close ui need to press button, proximity promt have a regular script but ui script to get player needs to be local but then i do ui script in local script its not working, but how can i access player who clicked in regular script(i can provide close script for ui, and proximity promt script to open, say what you need)
do you have a script for it so i can dive deeper
proximity promt script this type of script is regular:
local Promt = script.Parent
Promt.Triggered:Connect(function(player)
if player.PlayerGui.InGame.Enabled == false then
player.PlayerGui.InGame.Enabled = true
end
end)
close button script this needs to be regular too but if set to local working only 1 time (dont work, and i know player has not been announced anywhere):
local button = script.Parent
button.MouseButton1Click:Connect(function()
if player.PlayerGui.InGame.Enabled == true then
player.PlayerGui.InGame.Enabled = false
end
end)
Proximity Prompts | Documentation - Roblox Creator Hub
local ProximityPromptService = game:GetService("ProximityPromptService")
-- Detect when prompt is triggered
local function onPromptTriggered(promptObject, player)
end
-- Detect when prompt hold begins
local function onPromptHoldBegan(promptObject, player)
end
-- Detect when prompt hold ends
local function onPromptHoldEnded(promptObject, player)
end
-- Connect prompt events to handling functions
ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)
ProximityPromptService.PromptButtonHoldBegan:Connect(onPromptHoldBegan)
ProximityPromptService.PromptButtonHoldEnded:Connect(onPromptHoldEnded)
you do realize you can just do .PromptTriggered
on the client aswell?
i did something like this but its still dont work and script is local and located inside proximitypromt
local ProximityPromptService = game:GetService("ProximityPromptService")
local function onPromptTriggered(promptObject, player)
if script.Parent.Triggered then
if player.PlayerGui.InGame.Enabled == false then
player.PlayerGui.InGame.Enabled = true
end
end
end
ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)
it given errors in output and only work 1 time then dont work
LocalScripts do not work when theyâre descendants of Workspace
To run code on the client-side when the scriptâs in Workspace, youâll need to use a server Script, but make sure to set itâs RunContext
to Client
(Itâs set to Legacy
by default, which makes it run on the server-side)
This appears to be quite the common problem, I think the docs should make this information more prominent
thank you its is working but i see this error can you describe its bad or how i can fix this error:
Warning: The script with a non-legacy RunContext is parented to a container âStarterGuiâ, which will cause it to run multiple times. To avoid unintended behavior, consider setting the RunContext to âLegacyâ, disabling the script, or moving it to a different location.
Youâll still need to use regular LocalScripts for GUIs which are in StarterGui
Youâll also need to use regular LocalScripts for:
- Tools
- Client-side scripts in StarterCharacterScripts
- Scripts in StarterPlayerScripts
The problem
I do not support the run context property. Scripts should not be allowed to execute in environments they were not designated for. There are certain containers under the data model that do not support the execution of any script, and StarterGui
is one of them. The contents of StarterGui
are cloned into folder under each clientâs Player
instance called âPlayerGuiâ, a container that does allow script execution. By changing the run context of a script in StarterGui
, youâre enabling its original copy to execute in StarterGui
and its clone to execute in the âPlayerGuiâ folder.
The solution
Instead, use a LocalScript
under the GUI instance and reference the ProximityPrompt
in workspace:
local ProximityPrompt = -- Path.to.ProximityPrompt
local InGame = script.Parent
local function enableGUI()
InGame.Enabled = true
end
ProximityPrompt.Triggered:Connect(enableGUI)
Other game engines allow you to run client-side code no matter where theyâre executing, RunContext was added as a means to allow Studio to do so as well
The reason why it shouldnât be used in container services is because the scripts will attempt to run there as well, but using it in Workspace is perfectly safe
I recommended that you use RunContext because I assumed that the scriptâs parent is the ProximityPrompt, and ProximityPrompts are usually descendants of Workspace
ty man fixed error i jest needed local script not run context(bro why functions i dont prefer functions)
Youâre connecting a function to the event either way. Your approach uses a throwaway function instead. I prefer to use named functions as it improves consistency throughout the codebase while also providing a summary as to what the event listener does
idk then i use local functions it gives me more errors and harder to me i prefer use connected function to events
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.