My function isnt calling

code:

local function hit()
	game.StarterGui.DEATH.Enabled = true
	wait(2)
	game.StarterGui.DEATH.Frame.Transparency = 0.1
end

if game.Workspace.fencehit.Touched:Connect(hit) then
	
	end

no errors in the code and nothing prints in the output when i touch the “fencehit” part, but the UI isn’t changing, please help.

You don’t need an if statement for Touched event.

There are many things wrong with this. You are trying to place a connection in an if statement, and changing the values of a object in StarterGui which wont affect anything until the player respawns.

Assuming a GUI named DEATH is already in StarterGui and replicated to the client and that this is a local script, this would probably do the thing you want:

local plr = game.Players.LocalPlayer

workspace:WaitForChild("fencehit").Touched:Connect(function()
	plr.PlayerGui.DEATH.Enabled = true
	task.wait(2)
	plr.PlayerGui.DEATH.Frame.Transparency = 0.1
end)
1 Like

this code still didn’t do anything

What are you exactly trying to do, and where is this script located?

script is located inside the part i want to make the ui appear
and i am trying to make it so the ui appears and then slowly fades after 2 seconds (i already did the fade part of the code just didnt put it in the one i posted)

fencehit is the parent of the script

Is it a LocalScript, can you send a screenshot of it’s place in explorer?

its a local script and its the child of fencehit which is a child of workspace

image

LocalScripts don’t run when they are a descendant of Workspace. Try moving the script to StarterPlayer.StarterPlayerScripts

Tell me if I’m wrong but isn’t local scripts supposed to be in either starter gui or starter player/character scipts

thank you I got it to work! :slight_smile: :+1:

1 Like

Nice, don’t forget to mark my message as the solution

1 Like

Yes, they only run when parented to:

1 Like