My script is supposed to make a frame visible when someone clicks the part. However, it is not working.
function onClicked() game.StarterGui.PurchaseGui.PurchaseFrame.Visible = true end script.Parent.ClickDetector.MouseClick:connect(onClicked)
This script is inside the part that should be clicked.
Your script is working exactly as it should. It's updating the Gui in StarterGui
. This means that you won't see the change until your character reloads, as the contents of StarterGui
are cloned into each player's PlayerGui
folder on CharacterAdded
. To fix this, all you need to do is get the Gui from the PlayerGui
folder using a RemoteEvent
, because the server cannot do this.
--Server Script local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = Instance.new("RemoteEvent") --create remote Remote.Parent = ReplicatedStorage script.Parent.ClickDetector.MouseClick:Connect(function(player) Remote:FireClient(player,"") --you can send any data through the second argument end)
--Local Script, located somewhere like StarterPlayerScripts local ReplicatedStorage = game:GetService("ReplicatedStorage") local Remote = ReplicatedStorage:WaitForChild("RemoteEvent") --wait for remote local player = game:GetService("Players").LocalPlayer Remote.OnClientEvent:Connect(function(args) --the data you sent if player.PlayerGui:FindFirstChild("PurchaseGui") then player.PlayerGui.PurchaseGui.PurchaseFrame.Visible = true end end)
Note that Local Scripts
will only run when they are or were at some point a direct descendant of the player. This includes places like StarterPack
, StarterGui
, and StarterPlayerScripts
.