There is an error in the script

I try to play the part that shows a GUI and it doesn’t work. Who can help me, please?

game.Workspace.Lol.Touched:connect(function(hit)
local Open = game.StarterGui.BuyZoneUnderwater.Hijo
	if hit.Parent:FindFirstChildWhichIsA('Humanoid') then 
		Open.Visible = true
	end
end
1 Like

The GUI doesn’t work since all the visible GUI is parented to PlayerGui per Player. It is recommended to switch to a LocalScript handling those.

1 Like

StarterGui is a replicated service. So I don’t recommend setting a Gui variable by StarterGui, I recommend it by PlayerGui.

So, you have to do this in a LocalScript, and type in the following:

local Player = game.Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")

game.Workspace.Lol.Touched:Connect(function(hit)
local Open = PlayerGui.BuyZoneUnderwater:WaitForChild("Hijo")
if hit.Parent:FindFirstChildWhichIsA('Humanoid') then
Open.Visible = true
end
end

Let me know if this works.

when I touch it Dont work, bro

Are you getting any errors / warn in your output?

I have not received any error in the output :frowning:

Try putting your code into a function and calling the function when the part is touched, something like the following:

local function onTouched(hit)
--code here
end

game.Workspace.Lol.Touched:Connect(onTouched)

Also for future work use :Connect not :connect as it is deprecated.

Dont work

local Player = game.Players.LocalPlayer

local PlayerGui = Player:WaitForChild("PlayerGui")

local function onTouched(hit)

local Open = PlayerGui.BuyZoneUnderwater:WaitForChild("Hijo")

if hit.Parent:FindFirstChildWhichIsA('Humanoid') then

Open.Visible = true

end

game.Workspace.Lol.Touched:Connect(onTouched)

Do you see anything that appears in the output?

workspace.Lol.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('HumanoidRootPart') ~= nil then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player:WaitForChild('PlayerGui').BuyZoneUnderwater.Hijo.Visible = true
	end
end

Line 10

you forgot to put an end to close the if statement after Open.Visible = true

Oh, I’m sorry, it worked for me, thanks a lot.