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

Clickdetector not opening a gui?

Asked by 6 years ago

I've made a script where I create a part by doing Instance:

while wait(15)do
db = false
if db == false then
 if script.Parent.Humanoid.Health == 0 then
   db = true
   deadbody = Instance.new("Part", workspace)
   deadbody.Position = script.Parent.Torso.Position
   deadbody.Transparency = 0
   deadbody.CanCollide = true
   game.Workspace.nothing.hello123:Clone().Parent = game.Workspace.Part
end
end
end

And I cloned this hello123 (which is a part where there is a clickdetector and a localscript) in the Instance.new called part, as you can see. So I go on the LocalScript in nothing.hello123 and:

 db = true
 if db == true then     
    script.Parent.hello123.MouseClick:connect(function()
    game.StarterGui.ScreenGui.Frame.Visible = true
 end)

***So I test it and the part appears, but when I click on the part ( the cursor icon changes so it's not a clickdetector problem) it doesn't open. May you help me, please? ***

0
Probaly because local script won't work in workspace, put a server script and fire a client event Earthkingiv 51 — 6y
0
Still not working. Fixer1987 95 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

You’re trying to open the GUI through StarterGui, which is a place that is meant to clone all GUI to all players ONLY if they join/respawn.

Also, ClickDetectors have to be handled by server scripts, NOT local scripts. So you’ll also have to use RemoteEvents.

Here’s an example :

Server script (In the part with ClickDetector)

local event = game.ReplicatedStorage.RemoteEvent <- RemoteEvent placed in ReplicatedStorage

db = true
if db == true then     
   script.Parent.hello123.MouseClick:connect(function(plr)
   event:FireClient(plr)
end)

Local script (Placed in StarterGui)

local event = game.ReplicatedStorage.RemoteEvent

event.OnClientEvent:Connect(function(plr)
     plr.PlayerGui.ScreenGui.Frame.Visible = true
end)

So you have one script, one local script, and a RemoteEvent placed in ReplicatedStorage. When the player clicks the part, the script fires the RemoteEvent to the client, which then triggers the local script. The local script then makes a frame visible based on the player that clicked it (Which means this doesn’t affect all players).

Hoped this helped!

0
This is the error: Fixer1987 95 — 6y
0
19:13:30.336 - Players.Fixer1987.PlayerGui.LocalScript:4: attempt to index local 'person' (a nil value) 19:13:30.337 - Stack Begin 19:13:30.338 - Script 'Players.Fixer1987.PlayerGui.LocalScript', Line 4 19:13:30.339 - Stack End I inserted the RemoteEvent in ReplicatedStorage, LocalScript in StarterGui and the Script with the ClickDetector Fixer1987 95 — 6y
0
That local"person" is the function(plr) i just modified that plr in person Fixer1987 95 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
db = true
if db == true then     
   script.Parent.hello123.MouseClick:connect(function(Player)
   Player.PlayerGui.ScreenGui.Frame.Visible = true-- Not game.StarterGui.ScreenGui.Frame.Visible = true

end)
end

--[[

Everything else is fine

the code you used wont change the gui in game, what i showed you will ;)

--]]
0
Still not working. Fixer1987 95 — 6y
Log in to vote
0
Answered by 6 years ago

It worked, I just modified that plr.PlayerGui.ScreenGui.Frame.Visible = true in game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true.

Answer this question