Anyone knows why this won't work. No errors in the output

it seems fine, dont know what I have to fix

script.Parent.Touched:Connect(function(touch)
	game.StarterGui.ScreenGui.load.Visible = true
	wait(2)
	game.StarterGui.ScreenGui.load.Visible = false
end)

You’ll need to use the player’s PlayerGui and do that from there

script.Parent.Touched:Connect(function(touch)
    if touch.Parent:FindFirstChild("Humanoid") then
       local Player = game.Players:GetPlayerFromCharacter(touch.Parent)
       if Player then
          Player.PlayerGui.ScreenGui.load.Visible = true
          task.wait(3)
          Player.PlayerGui.ScreenGui.load.Visible = false
       end
    end
end)
1 Like

do you know how I can do that? Not really good at scripting.

Here, I posted it,
what it does -

Checks if the object has a humanoid inside → check if it’s a player → makes load visible for 3 seconds for the player, and then makes it invisible.

Is this correct?


game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

script.Parent.Touched:Connect(function(touch)
	game.PlayerGui.ScreenGui.load.Visible = true
	wait(2)
	game.PlayerGui.ScreenGui.load.Visible = false
end)

If you really want to do that from the client, then -

local PlayerUi = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

script.Parent.Touched:Connect(function(touch)
 if touch.Parent:FindFirstChild("Humanoid") then
       local Player = game.Players:GetPlayerFromCharacter(touch.Parent)
       if Player then
            PlayerUi.ScreenGui.load.Visible = true
	        task.wait(2)
  	       PlayerUi.ScreenGui.load.Visible = false
       end
  end
end)

I get this error

Workspace.NextPart.Script:1: attempt to index nil with ‘WaitForChild’

changed it to a local script, i dont get an error but it still wont work

Hey!
Localscripts will only run if they are descendant of something that is individual to the player!
Try moving the LocalScript to StarterCharacterScripts for instance and make a variable for the part:

local PlayerUi = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
local part = workspace:WaitForChild("[Partname]")

part.Touched:Connect(function(touch)
	if touch.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(touch.Parent)
		if Player then
			PlayerUi.ScreenGui.load.Visible = true
			task.wait(2)
			PlayerUi.ScreenGui.load.Visible = false
	    else
			print("Player does not exist!")
		end
	end
end)

NOTE: Change [Partname] in the part variable to the name of your part!

1 Like