Click gui giver script wont work

Here is my script it wont work idk why

local part = script.Parent

local click = part:WaitForChild("ClickDetector")

local click = script.Parent.ClickDetector

click.MouseClick:Connect(function(click)

local h = click.Parent:FindFirstChild("Humanoid")

local plyr = game.Players:FindFirstChild(h.Perant.Name)

local p = game.Players:FindFirstChild(plyr.PlayerGui.scGUI)

p.Enabled = true

end)
1 Like

Try doing
local p = plyr:FindFirstChild(“PlayerGui”):FindFirstChild(“scGUI”)

1 Like
local plyr = game.Players:FindFirstChild(h.Perant.Name)

“Perant”? I think you wanted to type Parent.

1 Like

nope it didnt work again same problem

You can just do

local part = script.Parent
local click = part:WaitForChild("ClickDetector")
--[[ local click = script.Parent.ClickDetector 
      ^ this line isn't necessary, you already defined it at line 2  ]]

click.MouseClick:Connect(function(player) -- change the parameter name to something other than "click" to not cause confusion between the variable and the argument
--[[
local h = click.Parent:FindFirstChild("Humanoid")
local plyr = game.Players:FindFirstChild(h.Perant.Name) <- you also misspelled "Parent"
local p = game.Players:FindFirstChild(plyr.PlayerGui.scGUI)

the parameter already sends the player who clicked it, you don't need to do anything fancy
to get the player ]]

local gui = player.PlayerGui.scGUI
gui.Enabled = true

end)
1 Like

Well, being unaware I can only assume on what you’re trying to achieve. I hope this helps though: script.Parent.MouseClick:Connect(function(player)
player.PlayerGui:FindFirstChild(“scGUI”).Enabled = true
end)

2 Likes

Also, click should be replaced with something that resembles the player. When it is clicked the parameter is what clicked it, which is the player. And the player does not contain a Humanoid. Instead it would be player.Character.Humanoid

2 Likes

First, Perant is spelled wrong, I would suggest doing

local click = script.Parent.ClickDetector

click.MouseClick:Connect(function(playerWhoClicked)
	local plrGui = playerWhoClicked:WaitForChild('PlayerGui')
	local gui = plrGui:FindFirstChild('scGUI')
	gui.Enabled = true
end)

No need to check for Humanoid, this should work

1 Like

It only works once idk why like when i close it and click on it again it wont appear why is this?

Try this script:

local part = script.Parent
local click = part.ClickDetector

click.MouseClick:Connect(function(player)
    player.PlayerGui.scGUI.Enabled = true
end)
1 Like
local part = script.Parent
local click = part:WaitForChild('ClickDetector')

click.MouseClick:Connect(function(player)
    player.PlayerGui.scGui.Enabled = true
end)
1 Like

It didnt work again idk why this is happening?

ok so I assume there’s a local script that closes it, try this

local part = script.Parent
local click = part:WaitForChild('ClickDetector')

click.MouseClick:Connect(function(player)
    player.PlayerGui.scGui.Enabled = false
    player.PlayerGui.scGui.Enabled = true
end)
1 Like

Ah yes this is the problem thank you for fixing this

If it’s being closed by a gui it will not work, because you’re making it visible on the server you need to close it on the server. This can be done with a remote event.

1 Like