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

How do I make things happen in StarterGui from a Workspace script? [Solved]

Asked by
2_MMZ 1059 Moderation Voter
4 years ago
Edited 4 years ago

Hi, so recently, I was trying to make my own game that features robot beings trying to come get you, while you have to collect 5 objects in order to beat them. But when you click on an object, it just disappears, and doesn't change the "Objects Left" in the StarterGui, it stays at 5? Anybody know how to fix this?

GIF Of this happening: https://gyazo.com/103f2a4eee89d853d5ebb45d14e4fc82

1 answer

Log in to vote
0
Answered by 4 years ago

Changing the StarterGui won't work because the contents of StarterGui are cloned to the player's PlayerGui on spawn. You need to access the player's PlayerGui from a click detector part and change the text label from there. This is how I'd do it:

local object = script.Parent
local objectValue = Instance.new("IntValue", object)

object.ClickDetector.MouseClick:connect(function(player)
    local playerGui = player.PlayerGui
    local gui = playerGui.ScreenGuiName.TextLabelName --change the names
    gui.Text = objectValue.Value + 1
    object:Destroy()
end)

Change the names above to your gui and you're good to go. Let me know if you are confused, I'll explain more.

0
Thanks, this helped. 2_MMZ 1059 — 4y
0
Don't forget to put [solved] in the title and accept my answer if it helped you, you'll also gain 2 points to your reputation. sidewinder44 20 — 4y
Ad

Answer this question