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

How to use screenGUI shop?

I parented the shop to each new player's camera since if it's in the playerGUI folder the brick isn't visible for the shop and you can't even click the gui buttons. Here's the code I have but it's not working. I've tried putting it in LocalScript and Server Script but it doesn't work and yes, I'm in Start Server -> Start Player.

Hierchy: Workspace +Camera(CurrentCamera) ++screenPiece +++back ++++shop stuff +++++buy1 ++++++script

local player = game.Players.LocalPlayer
local resources = player.resources
local tool = game.ServerStorage.Flashlight
local cost = 25

function onClick(player)
	if resources.Value >= cost then
		tool:Clone().Parent = player.Backpack
		resources.Value = resources.Value - cost
	end
end
script.Parent.MouseButton1Click:connect(onClick)

1 answer

Well, it is visible in PlayerGui. Last time I checked on the Wiki, the Player is only accessible from a SurfaceGui if the SurfaceGui is in the PlayerGui. You just need to set the Adornee. Put the ScreenGui itself, NOT THE BRICK, in StarterGui. Then have this following LocalScript in StarterGui as well:

repeat wait() until game.Players.LocalPlayer.PlayerGui
game.Players.LocalPlayer.PlayerGui["screenPiece"].Adornee = game.Workspace.Part -- Define the path

Your LocalScript however could use a bit fixing.

local tool = game.ServerStorage.Flashlight
local cost = 25

function onClick(player)
	if (resources.Value >= cost) then
		local player = game.Players.LocalPlayer -- Set the Player variables within the function otherwise it will error
		local resources = player.resources
		tool:Clone().Parent = player.Backpack
		resources.Value = resources.Value - cost
    end
end
script.Parent.MouseButton1Click:connect(onClick)

3 comments

0

Not working dude.

0

10:43:28.318 - PlayerGui is not a valid member of Players 10:43:28.319 - Script 'Players.Player2.PlayerGui.playerSetup', Line 1 10:43:28.319 - Stack End

0

Is it a LocalScript in starterGui?

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