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

Touched script not opening a gui as it should?

The script is supposed to open a gui, but it doesn't, why not?

script.Parent.Touched:Connect(function()
	game.StarterGui.UpgradesShop.MainFrame.Visible = true
end)

4 answers

✓ Accepted answer

Only a local script can interact with the PlayerGui, which is a section under every player in the game. Such as game.Players[The player's name].PlayerGui, and in turn local scripts only work inside a player instance such as Gui's, the player's character, etc.

To fix this issue, you could use Remote events, or move the LocalScript to a player instance, like StarterPlayerScripts inside of StarterPlayer and do something like:

local UpgradePart = game.Workspace.UpgradePart
local Player = game.Players.LocalPlayer
UpgradePart.Touched:Connect(function(hit)
Player.PlayerGui.UpgradesShop.MainFrame.Visible = true
end)

So, every player will have their gui inside the PlayerGui located inside the Player.

To Understand This, Try This Step:

  1. Test your game inside Roblox Studio

  2. Open Explorer

  3. Click on Players -> CodeWon -> PlayerGui

And there was where every Gui you make place in StarterGui will be cloned and placed inside the PlayerGui.


SOLUTION

Choose one type of the script!

Normal Script:

script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid")then
		local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
		
		Player:WaitForChild("PlayerGui").UpgradesShop.MainFrame.Visible = true
	end
end)

Local Script:

script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid")then
		local Player = game.Players.LocalPlayer
		
		Player:WaitForChild("PlayerGui").UpgradesShop.MainFrame.Visible = true
	end
end)

Hope It Helps!

local Players,showgui,a=game:GetService"Players",function(player)
player.PlayerGui.UpgradesShop.MainFrame.Visible=true
end,false;script.Parent.Touched:Connect(function(part)
if a then return end;a=true
pcall(showgui,Players:GetPlayerFromCharacter(part.Parent))
wait(1)a=false;end)

You should use PlayerGui.

Use this as a local script:

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

script.Parent.Touched:Connect(function()
	PlayerGui.UpgradesShop.MainFrame.Visible = true
end)

1 comment

0

NOTE: You cannot change the text in StarterGui before the character spawns. 

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