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.
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)
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 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.