Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How come this dialog choice won't open a gui in the starterGui?

So I have a script in the dialog choice and it's a simple 5 line open script when the choice is selected. But the thing that confirms where the ScreenGui is is underlined, and I don't know why.

---script---

script.Parent.DialogChoiceSelected:connect(function(player, choice)
	if StarterGui.ShopGui.Frame.Visible == false then
		StarterGui.ShopGui.Frame.Visible = true
	end
end)

What exactly went wrong in the script?

4 comments

0

Changing the visibility of a frame in StarterGui doesn't do anything for the player selecting the choice, it changes it for people that have yet to join the game, because objects in StarterGui are replicated to a player when they join the game.

0

If this is being done in a LocalScript, do player.PlayerGui.ShopGui.Frame.Visible instead of StarterGui.ShopGui.Frame.Visible

0

And if this is being done in a server script, you might want to use a RemoteEvent

0

I will post an answer because gotta get those rep points somehow y'kno

1 answer

✓ Accepted answer

I am going to reiterate what I said earlier in the initial comments I made.

You are not showing the ShopGui for the player that selected the dialog choice, you are changing the visibility of the ShopGui's frame for the ShopGui that is in StarterGui. When a player joins the game, they will receive a copy of this ShopGui that is in StarterGui.

What you need to do is modify the ShopGui inside of the Player's PlayerGui.

If this is being done in a LocalScript, it will be a simple fix.

Note: :connect is deprecated, use :Connect just to be safe because Roblox could remove the functionality of :connect in the future.

script.Parent.DialogChoiceSelected:Connect(function(player, choice)
    if player.PlayerGui.ShopGui.Frame.Visible == false then
        player.PlayerGui.ShopGui.Frame.Visible = true
    end
end)

Now, that's the solution for your problem if you're using a LocalScript.

This is the solution if you're using a server script.

  1. Insert a RemoteEvent in ReplicatedStorage.
  2. Insert a LocalScript into StarterGui.

In the LocalScript, type the following.

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local Player = game.Players.LocalPlayer
local Gui = Player:WaitForChild("PlayerGui"):WaitForChild("ShopGui")
local Frame = Gui:WaitForChild("Frame")

Remote.OnServerEvent:Connect(function()
	if Frame.Visible == false then
		Frame.Visible = true
	else
		Frame.Visible = false
	end
end)

Modify the server script.

local Remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

script.Parent.DialogChoiceSelected:Connect(function(player, choice)
    Remote:FireClient(player)
end)

It appears that you inserted the "choice" parameter for this event listener, but did not use it. You don't have to insert parameters that you aren't going to use, unless that parameter is returned(chronologically) before ones that are you are going to use.

This is the full solution. I am a bit drowsy right now, so I could have made some errors. If anyone spots one, or multiple, point it or them out please.

1 comment

0

I'll check it.

This discussion is preserved as it was. New answers, comments, and votes are closed.