Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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?

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. Unhumanly 152 — 5y
0
If this is being done in a LocalScript, do player.PlayerGui.ShopGui.Frame.Visible instead of StarterGui.ShopGui.Frame.Visible Unhumanly 152 — 5y
0
And if this is being done in a server script, you might want to use a RemoteEvent Unhumanly 152 — 5y
0
I will post an answer because gotta get those rep points somehow y'kno Unhumanly 152 — 5y

1 answer

Log in to vote
1
Answered by
Unhumanly 152
5 years ago
Edited 5 years ago

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.

0
I'll check it. vincentthecat1 199 — 5y
Ad

Answer this question