Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why my script to appear GUI when you click block doesn't works?

Hello! I'm trying to make GUI appear when I touch block. I did this script below but it doesn't works, also I don't have any errors, any ideas what should I change? (script is in local script)

local Player = game.Players.LocalPlayer

local function change(hit)
	if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
		
		Player.PlayerGui.UniformGui.Frame.Visible=true
		
	end
end


script.Parent.Touched:Connect(change)

1 answer

LocalScripts will not run in the Workspace if they are not parented to a player's Character. Think of it this way:

A local script relies on a client to function properly. Without a client there is nothing "local" to refer to, because only the server exists, and the server is not "local". If a local script is parented to StarterGui, the script gets cloned to PlayerGui, and since PlayerGui is associated with a player, the script is able to function. However, if you put it somewhere that it will never obtain a client from, it will cease to function.

You can do this in a local script not parented to the Workspace unless under the Character by referring to the part to be touched as a separate Instance not initially associated with the local script. It will then be able to obtain the script signal and allow it to fire.

This discussion is preserved as it was. New answers, comments, and votes are closed.