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? ***
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 :
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 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!
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 ;) --]]
It worked, I just modified that plr.PlayerGui.ScreenGui.Frame.Visible = true in game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true.