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

This ClickDectector Open GUI script isn't working. Why?

Asked by 6 years ago

My script is supposed to make a frame visible when someone clicks the part. However, it is not working.

1function onClicked()
2    game.StarterGui.PurchaseGui.PurchaseFrame.Visible = true
3end
4 
5script.Parent.ClickDetector.MouseClick:connect(onClicked)

This script is inside the part that should be clicked.

1
You're modifying the StarterGui instead of the actual gui the player has. Just use a localscript for the onclicked event, and check if the person who clicked it was the localplayer. If it was, then enable the gui. CodyDev 70 — 6y
1
MouseClick is not responsive to Local Scripts. it must be used on the server Gey4Jesus69 2705 — 6y
1
no, not true, local scripts can listen for the MouseClick event theking48989987 2147 — 6y
0
ok roblox changed that bc the wiki used to explicitly say otherwise. gg Gey4Jesus69 2705 — 6y

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 years ago

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.

1--Server Script
2 
3local ReplicatedStorage = game:GetService("ReplicatedStorage")
4local Remote = Instance.new("RemoteEvent") --create remote
5Remote.Parent = ReplicatedStorage
6 
7script.Parent.ClickDetector.MouseClick:Connect(function(player)
8   Remote:FireClient(player,"") --you can send any data through the second argument
9end)

01--Local Script, located somewhere like StarterPlayerScripts
02 
03local ReplicatedStorage = game:GetService("ReplicatedStorage")
04local Remote = ReplicatedStorage:WaitForChild("RemoteEvent") --wait for remote
05local player = game:GetService("Players").LocalPlayer
06 
07Remote.OnClientEvent:Connect(function(args) --the data you sent
08   if player.PlayerGui:FindFirstChild("PurchaseGui") then
09      player.PlayerGui.PurchaseGui.PurchaseFrame.Visible = true
10   end
11end)

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.


Resources:

Remote Events

Local Script


Accept and upvote if this helps!

0
It says that local player is not a valid member of players. ChasingNachos 133 — 6y
0
sorry i accidentally said LocalPLayer. i edited it Gey4Jesus69 2705 — 6y
Ad

Answer this question