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
Your problem is that you are trying to compare the name of the dialog choice, but instead you should be comparing the UserDialog property of it.
Just replace the function you have to this: (you'll know which one)
script.Parent.DialogChoiceSelected:Connect(function(Player, DialogChoice) if DialogChoice.UserDialog == "Yes" then print("Attempting to open " .. Player.Name .. "'s shop") ManipulateStoreEvent:FireClient(Player, "Open") table.insert(PlayersUsing, Player) end end)
If anything else doesn't work, let me know.