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

ClickDetector Script that Changes GUI no Longer Works?

Asked by 5 years ago

So, I want to have a feature in my game where certain objects can be clicked to show some flavor text on the player's screen. I decided to go about this by putting a ScreenGui with a TextLabel in it in Player.Gui. I put a ClickDetector and a script in a model so that when the model is clicked, the TextLabel will be activated and fadeout, deactivating afterwards. To prevent bugs, the ClickDetector is only usable when the TextLabel is deactivated. Here's my script:

local click = script.Parent.ClickDetector
local msg = "A bit late to go outside..."

click.MouseClick:Connect(function(plr)
    local text = plr.PlayerGui.ScreenGui.TextLabel
    if text.Active then
    else
        text.Active = true
        text.Text = msg
        text.TextTransparency = 1
        for a=1,0,-.01 do
            text.TextTransparency = a
        end
        text.Active = false
    end
end)

However, when I click the model, it spits out an error at me.

'ScreenGui is not a valid member of PlayerGui'

It seems like, for some odd reason, it doesn't think ScreenGui exists??? I've used this method before and it worked fine, so there must have been some update that broke it.

0
Then it's because there is no child called ScreenGui inside PlayerGui. Keep in mind StarterGui is cloned locally the guis created only exist on the client and not the server. gullet 471 — 5y
0
Oh, thanks, I didn't know it was local (Although I don't think it was always like that). How might I go about accessing it with a ClickDetector, then? DapperDashel 0 — 5y
0
Use a RemoteEvent and :FireClient SirDerpyHerp 262 — 5y

1 answer

Log in to vote
0
Answered by
angeI1001 123
5 years ago

That is because the server cannot access the client, and the client cannot access the server. To fix this, you'd need to use a RemoteEvent.

More about RemoveEvents: https://www.robloxdev.com/api-reference/class/RemoteEvent

Hope this helped you.

Ad

Answer this question