Why doesnt this code work

i dont know how to script at all but im not sure why this code doesnt work

its supposed to make a ui apear when you touch a part

-- if script.Parent.Touched:Connect(function)  then
	game.StarterGui.Loading.Enabled = true
end
2 Likes

You can’t do it like that, but maybe you can like that:


if script.Parent.Touched:Wait() then
    
end

1 Like

wdym i dont get what your saying
also how would i make it fade in

1 Like

Can you show a picture of the gui in explorer

script.Parent.Touched:Connect(function(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
      game:GetService("Players"):GetPlayerFromCharacter(hit.Parent).PlayerGui.loading.Enabled = true
   end
end

Btw you have to enable the gui in playergui not startergui because the game has already started

1 Like

its pretty simple just a screengui called Loading and a textlabel in it

1 Like

I think this should work

script.Parent.Touched:Connect(function(hit)
    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)

    if player then
        local gui = player:WaitForChild("PlayerGui"):FindFirstChild("Loading")

        if gui then
            gui.Enabled = true
            
            local textLabel = gui:FindFirstChild("YourTextLabel") -- change this

            if textLabel then
                for i = 1, 0, -0.1 do
                    textLabel.BackgroundTransparency = i
                    task.wait(0.1) -- you can change that too
                end
            end
        end
    end
end)
3 Likes

You can try:

script.Parent.Touched:Connect(function(hit))
 if game.Players:FindFirstChild(hit.Parent.Name) ~= nil then 
     game.Players:FindFirstChild(hit.Parent.Name).PlayerGui.Loading.Enabled = true
end
end)

Not sure if this will work since I just wrote it in mobile.

1 Like

You dont check if hit.parent has a humanoid so it could be baseplate that touches it causing an error

thank you so much it works!

sry how would i make it so it will fade out also

When do you want it to fade out?

sry i was doing something else but i want it to fade out like 3 seconds after it apears