If you click a part, a ScreenGui should show up only for the client. It's supposed to be a dialog box like in an rpg. However, this works in Studio, but not when published. What can I do to fix this?
local ClickerModule = require(343254562)
local clickEvent = ClickerModule.RemoteEvent
local interactiveParts = {}
local activationDistance = 14
local guiOpen = false
local changingState = false
for i, v in pairs(script.Parent:GetChildren()) do
if v.Name == "Interactive" then
table.insert(interactiveParts, v)
end
end
local function distanceToCharacter(player, part)
local character = player.Character
if character then
local torso = character:FindFirstChild("Torso")
if torso then
return((torso.Position - part.Position).magnitude)
end
end
return math.huge
end
clickEvent.OnServerEvent:connect(function(player, part)
local isPart = false
for i = 1, #interactiveParts do
if part == interactiveParts[i] then
isPart = true
end
end
if isPart and player.Character and distanceToCharacter(player, part) <= activationDistance then
if guiOpen == true and changingState == false then
changingState = true
player.PlayerGui.Dialog.Test.Frame1.Visible = true
changingState = false
guiOpen = false
elseif changingState == false then
changingState = true
player.PlayerGui.Dialog.Test.Frame1.Visible = true
changingState = false
guiOpen = true
end
end
end)

3 comments
Just to add something, I'm not sure if this would require a RemoteEvent or not. I'm not experienced with using those.
Are there any errors in the output that you can share?
There are none.