So I’m trying to make a snowboard game and I set up the Proximity prompts but when I activate one of the prompts it activates all of them. How could I fix this?
local ProximityPromptService = game:GetService("ProximityPromptService")
local function onPromptTriggered(promptObject, player)
print(player.Name.. " mounted CoDev board")
end
ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)
The PromptTriggered event of the ProximityPromptService will listen for any ProximityPrompt in the game to be activated. If you’d like to continue using that, you could add in conditional statements that will check which prompt was activated and fulfill a specific action based on that.
Otherwise, if you’re looking to do this on an individual level, I’d suggest utilizing the Triggered / TriggerEnded events of the specific ProximityPrompt Instance you want to listen for:
Examples
ProximityPromptService
local ProximityPromptService = game:GetService("ProximityPromptService")
local function onPromptTriggered(promptObject, player) -- promptObject refers to the specific ProximityPrompt that was activated
if promptObject.Name == "SnowboardPrompt" then -- Checks for the name of the prompt before doing something
-- Activate another function/do something related to the Snowboards
elseif promptObject.Name == "DoorPrompt" then -- If its name was "DoorPrompt", for example
-- Same as above, except for something related to the functionality of a door
end
end
ProximityPromptService.PromptTriggered:Connect(onPromptTriggered) -- Whenever any Prompt in the game is activated, the function called "onPromptTriggered" will be run
Individual ProximityPrompt
local ProximityPrompt = script.Parent -- References a specific ProximityPrompt
local function onPromptTriggered(player)
-- Because you know which prompt is being referred to, you can immediately continue
end
ProximityPrompt.Triggered:Connect(onPromptTriggered) -- Whenever the referenced prompt has been activated, it'll run the function called "onPromptTriggered"
Resources
Additional information can be found on the Roblox Developer Hub: