Basically, I had a script that was using ClickDetector and it just doesn’t fit what I want for my game anymore
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if not player.PlayerGui:FindFirstChild("ShopGUI") then
local clone = script.Parent.ShopGUI:Clone()
clone.Parent = player.PlayerGui
clone.Cam.Disabled = false
end
if (player.Character.Torso.Position - script.Parent.Torso.Position).magnitude < 10 or (player.Character.Torso.Position - script.Parent.Torso.Position).magnitude < 10 then
elseif (player.Character.Torso - script.Parent.Torso).magnitude > 10 or (player.Character.Torso - script.Parent.Torso) then
player.PlayerGui:WaitForChild("ShopGUI"):Destroy()
player.Character.Humanoid.Died:connect(function()
player.PlayerGui:FindFirstChild("ShopGUI"):Destroy()
end)
end
end)
And I turned it into this after reading a bit on the subject (Clickdetector to E prompt)
local ClickDetector = script.Parent.ClickDetector
local sound = script.Parent.pickup
local debounce = false
local prompt = script.Parent.ProximityPrompt
prompt.Triggered:Connect(function(player)
if not player.PlayerGui:FindFirstChild("DealerGui") then
local clone = script.Parent.DealerGui:Clone()
clone.Parent = player.PlayerGui
clone.Cam.Disabled = false
end
if (player.Character.Torso.Position - script.Parent.Torso.Position).magnitude < 10 or (player.Character.UpperTorso.Position - script.Parent.Torso.Position).magnitude < 10 then
elseif (player.Character.Torso - script.Parent.Torso).magnitude > 10 or (player.Character.Torso - script.Parent.Torso) then
player.PlayerGui:WaitForChild("DealerGui"):Destroy()
player.Character.Humanoid.Died:connect(function()
player.PlayerGui:FindFirstChild("DealerGui"):Destroy()
end)
end
end)
I used another one that had EnumKey & UIS but I’m really not getting it
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, processed)
if input.UserInputType == Enum.UserInputType.E then
--perform action(s)
end
end)
I’d like to use ProximityPrompt, which show the user “E to interact” or something similar
It’s not a GUI but more like a ‘E to open gui’ near a NPC so yeah
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)
But if you’d like to be able to change the key for the Prompt for a example
Hold E to activate or Hold R to activate then inside of the Prompt property you can configure all of that, if you want to be able to change it inside of the script.
prompt.KeyboardKeyCode = “E”
Also I recommend returning the code if the player isn’t near as it would prevent exploiters from calling it just a little bit.
Lastly I recommend putting your script inside the Prompt so you can do script.parent but what ever is simpler to you.
-- Services --
local Debris = game:GetService("Debris")
-- Instances --
local ProximityPrompts = script["Proximity Prompts"]
local Settings = script.Settings
-- Variables --
local proximityPrompts = {}
local connections = {}
local screenGuis = Settings.ScreenGuis:GetChildren()
local timeUntilDelete = Settings.Time.Value
-- Functions --
local function getProximityPrompts()
for index, child in pairs(ProximityPrompts:GetChildren()) do
if child:IsA("ObjectValue") then
local prompt = child.Value
if prompt:IsA("ProximityPrompt") then
table.insert(proximityPrompts, prompt)
end
end
end
end
local function onTriggered(player)
local playerGui = player:WaitForChild("PlayerGui", 5)
if not playerGui then return end
if (player.Character.Torso.Position - script.Parent.Torso.Position).magnitude < 10 or (player.Character.UpperTorso.Position - script.Parent.Torso.Position).magnitude < 10 then
return end
for index, screen in pairs(screenGuis) do
for index, child in pairs(playerGui:GetChildren()) do
local childCloneSource = child:FindFirstChild("CloneSource")
if childCloneSource then
if childCloneSource.Value == screen then
child:Destroy()
end
end
end
local newScreen = screen:Clone()
local cloneSource = Instance.new("ObjectValue")
cloneSource.Name = "CloneSource"
cloneSource.Value = screen
cloneSource.Parent = newScreen
newScreen.Parent = playerGui
Debris:AddItem(newScreen, timeUntilDelete)
end
end
-- Code --
getProximityPrompts()
for index, prompt in ipairs(proximityPrompts) do
local connection = prompt.Triggered:Connect(onTriggered)
table.insert(connections, connection)
end
Would that work ?
My friend Kingpie helped a bit with organising everything & tried to help me making it secure from exploiters
I removed most the code just to check the prompt, it works. If you had like to test what exploiters have access to you could run it as the client (on Studio)
Go near a Prompt and extend the distance to over the 10 so probably 20 and walk til you can see it disappears and appear again I recommend using like print or warn when you’re testing so you could see if it works or not. Also I recommend so you don’t have any issues in the future to always put your security checks at the top
if (player.Character.Torso.Position - script.Parent.Torso.Position).magnitude < 10 or (player.Character.UpperTorso.Position - script.Parent.Torso.Position).magnitude < 10 then return end
that should be above
local playerGui = player:WaitForChild("PlayerGui", 5)
Lastly you don’t really need to have two checks but I suppose it helps be more specific, I would normally just check if the Torso is near or UpperTorso (If R15)
But the system looks pretty neat if I would say so myself.