Currently making something which requires proximity prompts on players.
The problem is that I am unable to figure out how to handle the prompts being triggered, as I can’t just list out all of the triggered events (since there can be different amounts of players in the server)
Looked around and found a tutorial, but the tutorial used a triggered event inside the characterAdded event by connecting it after assigning the prompt to the character, which i’ve heard wasn’t a good idea.
oh yea and i thought maybe I could put all the events in a table, but since the thing thats supposed to handle the event is in another script, i would have to transfer the table (or merge the 2 scripts, but i’ve also heard that thats not a good idea)
The only time i would say to use Multiple Events for one is maybe to get a Specific Data you cant normally get by itselft, Like with the character in a Server Script
Players.PlayerAdded:Connect(function(Plr)
Plr.CharacterAdded:Connect(function(char)
char -- The Players Character
end)
end)
For the Triggered with the ProximityPrompt, its not really nessecary as you can access the Player who clicks it
Prompt.Triggered:Connect(function(Player)
print(Player) -- Player who clicked
end)
yea but i can have from like 3 triggered events up to hundreds (since I have to re-add the prompt everytime the player dies) so I cant just use a single triggered
(you might’ve misunderstood me, I have multiple proximity prompts, not multiple players clicking on them lol)
the table thing would probably work, but I would have to either use a bindable event (or something else, idk) to transfer it to another script, or mix it in with a script that already does something else
(the remote event is supposed to kill the player when clicked, if that helps)
srry for changing the solution status multiple times lol (was thinking about how it would work and I kept thinking i got it but then i didn’t)
anyways tho, do you mean to use the modulescript to relay the information or to construct it? because the table would have to change each time a player spawns (as a new proximity prompt is added to the player each time, while the old one is removed together with the player’s character)
btw, do you think I could loop through game.Players, and use player.Character:FindFirstChild() to construct a list of the remote events in the script I need it in?
Since the project has rounds, I can construct the remote events list every time a round starts
local mod = require(module) -- Gets Module Info (Path your Module)
-- PlayerAdded connection
Player.CharacterAdded:connect(function(c) -- Character Added
-- create a ProximityPrompt Here
mod.Connections[Player.Name] = Prompt.Triggered:Connect(function) -- Event
c.Humanoid.Died:Connect(function() -- If Player dies
mod.Connections[Player.Name]:Disconnect() -- Disconnects Event
mod.Connections[Player.Name] = nil -- Removes Event from List
end)
end)
actually quick question, but would a script like below cause any issues?
since it seems like you have to connect the event in the characterAdded event anyways as you did in the script you gave.
Player.CharacterAdded:connect(function(c)
-- Proximity prompt created
connection = Prompt.Triggered:Connect(function)
-- event here
end)
c.Humanoid.Died:Connect(function()
connection:Disconnect()
end)
oh yea and since im killing the player (and removing the body, so probably using something like player:Destroy()) I don think I event need to disconnect the connection do I (since the proximity prompt is also destroyed on death)