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)
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)
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:
Test your game inside Roblox Studio
Open Explorer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
NOTE: You cannot change the text in StarterGui before the character spawns.