PlayerGui problems

Hello,

So I have a script in the workspace and NOT a LocalScript cause the LocalScript doesn’t works there ofcourse. Now that script in the workspace chekcs how many trees there are left. And if there are 0 trees left the main menu needs to open. But I can’t acces the PlayerGui with a normal Script.

So does anyone know how I can finally solve this? PLEASE HELP!

Remote Events are a way of communicating between the client and the server. Once you want the main menu to open, fire a remote event from your script in workspace to a local script in PlayerGui.

From the local script, once the event is detected, you can now easily show the main menu.

just use the playeradded parameter and get playergui

1 Like

Can you show me how? Cause I’ve already tried to do that but didn’t worked.

I did that like 1 hour ago and that didn’t worked but for somehow it did worked in one of my games that I created this past year(2021).

send your script and I’ll add a playeradded to it and make it work

First, you need to create a RemoteEvent in ReplicatedStorage. For this example, we will name it “OpenMenu”.

Now from the server, once there are no trees left, fire the RemoteEvent to the client.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local OpenMenu = ReplicatedStorage.OpenMenu

-- your code
OpenMenu:FireAllClients()

Now, make a local script under the gui you want to show.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local OpenMenu = ReplicatedStorage.OpenMenu

local menu = script.Parent

OpenMenu.OnClientEvent:Connect(function()
        menu.Visible = true
end)

@iscriptfast, @Friendly4Crafter
This is the current script;

local log = script.Parent.Trunk
local leaves = script.Parent.Leaves1
local hits = 0 
local totalHits = 5

local treeLeft = game.Workspace.TreeArea.Trees.TreeCount

print(hits)


log.Touched:Connect(function(hit, player)
	if hit.Parent.Name == "WoodenAxe" then
		hits = hits + 1

		if hits == totalHits then
			print(hits)

			treeLeft.Value -= 1

			hits = 0
			log.Anchored = false
			leaves.Anchored = false
			leaves.CanCollide = false
			wait()
			log.Rotation = Vector3.new(45,0,0)
			wait(3)
			log:Destroy()
			

			


			local value = game.Workspace.TreeArea.Trees.TreeCount

			local script = script.Parent

			local TreeFolder = game.Workspace.TreeArea

			local Players = game:GetService("Players")

			local BindableEvent = game:GetService("ReplicatedStorage"):WaitForChild("TreeCheck")
			print("yea;;; The first one")

			if value.Value == 0 then
				local function showGui(player)

					TreeFolder:Destroy()

					local HomeMenu = player.PlayerGui.HomeMenu
					HomeMenu.Enabled = true
				end
				
				showGui()
			end
			
		end
	end
end)


I edited the scripts and nothing… The main menu doesn’t shows.

I put the scripts that were in the workspace in ServerScriptService and the LocalScript inside the GUI. And I changed them to what you said with the RemoteEvents. And still it doesn’t works.

change this to:

showGui(Players:GetPlayerFromCharacter(hit.Parent.Parent))

“WoodenAxe” is a tool, I assume

also, “Touched” event doesn’t gives you a “player” argument, so no need to keep it