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

Why won't my text changing script work from inside a model?

I'm helping a friend make a game, and I'm testing some basic scripts. For some reason, a script that changes a text in StarterGui won't work.

This is the script I'm using:

local Man = script.Parent.Parent local Mission = workspace.StarterGui.Gu.Frame.Mission

function myfunction() Mission.Text = "Mission: None" wait(0.1) Man:Destroy()

end

script.Parent.ClickDetector.MouseClick:connect(myfunction)

I've tried several different ways to fix the script, but it won't work. Am I using an outdated way of changing text in GUI's? If I've made a stupid mistake, It'd help to point it out.

1 answer

✓ Accepted answer

StarterGui is not a valid member of workspace, it is a child of game, and it’s own service. It should not be referenced either when attempting to modify the User Interface, as it is not the authentic location of the active GUIs. Upon a Client connecting to the Server, it’s own UI is created by cloning the contents of StarterGui into a local container named PlayerGui. You’ll need to reference the GUI Object from this standpoint to properly modify the User Interface.

local ClickDetector = script.Parent

ClickDetector.MouseClick:Connect(function(PlayerClicked)
    local PlayerGui = PlayerClicked:FindFirstChild("PlayerGui")
    if (PlayerGui) then
        local MissionLabel = PlayerGui.Gu.Mission
        MissionLabel.Text = "Mission: None"
    end)
end)

1 comment

0

ehh?

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