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

Nothing happens - No output errors, Why doesnt the gui appear?

So, i have a localscript that enables a gui on touch.

local function onTouch(part)
	game.StarterGui.ScreenGui.Enabled = true
	game.StarterGui.ScreenGui.TextLabel.Text = "###### #### ## Who are you?! ###"
	game.StarterGui.ScreenGui.NameText.Text = "Bacon Hair"
	wait(8)
	game.StarterGui.ScreenGui.TextLabel.Text = "###### # #### ## The secret is near the coldest place here.. ##### ## ###"
	wait(8)
	game.StarterGui.ScreenGui.Enabled = false
end

script.Parent.Touched:Connect(onTouch)

ive tried different functions and stuff, switching around, it hasnt worked. if you are looking for an output error, there is no output errors. if anybody needs more information, ill be glad to elaborate.

3 comments

0

Local script's don't work on touch events!!

0

oh

0

still doesnt work

3 answers

✓ Accepted answer

First of all, change the script type to a server script.

If you change a gui on StarterGui, changes will only be seen by the player when they respawn, if you want to make players able to see the edits, you need to change on PlayerGui

local function onTouch(hit)
    local player =  game.Players:GetPlayerFromCharater(hit.Parent) --Tryes to get player from the part that touched, if is a player
    
    if player then --A player touched
        player.PlayerGui.ScreenGui.Enabled = true
        player.PlayerGui.ScreenGui.TextLabel.Text = "###### #### ## Who are you?! ###"
        player.PlayerGui.ScreenGui.NameText.Text = "Bacon Hair"
        wait(8)
        player.PlayerGui.ScreenGui.TextLabel.Text = "###### # #### ## The secret is near the coldest place here.. ##### ## ###"
        wait(8)
        player.PlayerGui.ScreenGui.Enabled = false
end

script.Parent.Touched:Connect(onTouch)

5 comments

0

You forgot an extra end but its ok

0

It says unknown global hit

0

I've fixed it, check my script.

1

@ScriptsALot I fixed it

0

it worked, i had to do some changes, like changing it to hit, you spelling character wrong, and that extra end

Insert a remote event in replicated storage. DO NOT name it and insert a script onto the part that you want to touch. ( not a local script since it doesn't work on the workspace as it is local )

That being done, the touched event script would be:

script.Parent.Touched:Connect(hit)
        if game.Players:GetPlayerFromCharacter(hit.Parent) then
      game.ReplicatedStorage.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
      end
end)

Note that remote event's fire only on servers if used on local scripts.

Now, insert a local script into the Screen Gui and it would be as follows.

local playerGui = game.Players.LocalPlayer.PlayerGui -- Define playerGui

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function()
     playerGui.ScreenGui.Enabled = true
     playerGui.ScreenGui.TextLabel.Text = "###### #### ## Who are you?! ###"
     playerGui.ScreenGui.NameText.Text = "Bacon Hair"
    wait(8)
    playerGui.ScreenGui.TextLabel.Text = "###### # #### ## The secret is near the coldest place here.. ##### ## ###"
    wait(8)
    playerGui.ScreenGui.Enabled = false
end)

Let me know if this works..

Please upvote and select this as your answer if it helped.

7 comments

0

You have to change gui on PlayerGui, changing it on StarterGui will only have effect on respawn

0

so do i insert a local script into the remote event?

0

so do i insert a local script into the remote event?

0

so do i insert a local script into the remote event?

0

How do i get PlayerGui

0

If you have the player instance then you can do player.PlayerGui

0

Fixing it..

LocalScripts don't run if they are not a descendant of ReplicatedFirst or the LocalPlayer, which is one of your issues with your script. Another one would be the fact that you are making the changes to StarterGui, not the PlayerGui, meaning if the ScreenGui has ResetOnSpawn disabled, it'll never change, otherwise, it'll change when the player resets, which is not too often depending on the game. This is a "fixed" script I made, for your case.

local GUI_NAME = "ScreenGui"
local TEXT_LABEL_NAME = "TextLabel"
local NAME_LABEL_NAME = "NameText"
local MESSAGE_LENGTH = 8

local Players = game:GetService("Players")
local Client = Players.LocalPlayer

local PlayerGui = Client:WaitForChild("PlayerGui")
-- Path to the part that is gonna be touched
local TouchPart = ...

local function OnTouch(Hit)
	local Character = Client.Character
	-- Checks if the character exists, before making a call to check if
	-- the character is the ancestor of Hit.
	if not Character then
		return
	end
	if not Character:IsAncestorOf(Hit) then
		return
	end
	-- I only get the Gui here, as the Gui may have changed if the player resetted.
	local Gui = PlayerGui:FindFirstChild(GUI_NAME)
	if not Gui then
		return
	end
	-- This acts as a "Debounce"
	if Gui.Enabled then
		return
	end
	local TextLabel = Gui:FindFirstChild(TEXT_LABEL_NAME)
	local NameLabel = Gui:FindFirstChild(NAME_LABEL_NAME)
	if not TextLabel or not NameLabel then
		return
	end
	Gui.Enabled = true
	TextLabel.Text = "###### #### ## Who are you?! ###"
	NameLabel.Text = "Bacon Hair"
	wait(MESSAGE_LENGTH)
	TextLabel.Text = "###### # #### ## The secret is near the coldest place here.. ##### ## ###"
	wait(MESSAGE_LENGTH)
	Gui.Enabled = false
end
TouchPart.Touched:Connect(OnTouch)

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