So I'll start off by explaining how I have my Dialog setup; I have the Dialog in an npc's head in the Workspace, the following code is inside a Script inside the Dialog. The script works locally but not on a server. I've been told that I should be handling this locally but I have no idea how I would do so. Any and all help is greatly appreciated!
Edit: I forgot to specify what wasn't working, the print on line 11 and everything following it isn't firing on the server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ManipulateStoreEvent = ReplicatedStorage.RemoteEvents:WaitForChild("ManipulateStoreEvent")
local ShopKeeper = script.Parent.Parent.Parent
local Position = ShopKeeper.HumanoidRootPart.CFrame.p
local Dialog = script.Parent
local PlayersUsing = {}
script.Parent.DialogChoiceSelected:Connect(function(Player, DialogChoice)
if DialogChoice.Name == "Yes" then
print("Attempting to open " .. Player.Name .. "'s shop")
ManipulateStoreEvent:FireClient(Player, "Open")
table.insert(PlayersUsing, Player)
end
end)
function getPlayerPosition(Player)
local Character = game.Workspace:FindFirstChild(Player.Name)
if Character then
return Character.HumanoidRootPart.CFrame.p
end
end
function removePlayerFromPlayersUsing(PlayerRemoving)
for Index, Player in pairs(PlayersUsing) do
if PlayerRemoving == Player then
table.remove(PlayersUsing, Index)
end
end
end
while wait(0.5) do
if Dialog.InUse then
for _, Player in pairs(PlayersUsing) do
local Magnitude = (Position - getPlayerPosition(Player)).magnitude
if Magnitude > Dialog.ConversationDistance then
print("Attempting to close " .. Player.Name .. "'s shop")
ManipulateStoreEvent:FireClient(Player, "Close")
removePlayerFromPlayersUsing(Player)
end
end
end
end

2 comments
Also remember the DialogChoiceSelected event is only for dialogs, not dialogchoices.
I personally didn't get this working, I opted to create my own custom dialog because I figured it would allow for more functionality and creativity. But I've been informed this is working for other individuals.