game.StarterGui.ScreenGui.TextButton.LocalScript
TriggerCount = 0 local function TriggerCountAdd() TriggerCount = TriggerCount + 1 print(TriggerCount) end script.Parent.MouseButton1Click:Connect(function() TriggerCountAdd() end) if TriggerCount == 3 then local Trigger = Instance.new("Folder", game:GetService("ReplicatedStorage")) Trigger.Name = "FirstWave" end
game.ServerScriptService.Script
repeat wait() until game.ReplicatedStorage:FindFirstChild("FirstWave") workspace.BarrierCrush1:Destroy()
Maybe you need to put your GUI script in a loop. I'm not sure, but maybe your if statement isn't even running.
Ok, version 2 of my answer:
Use a remote event to contact the server. Here is a page on remote events and functions. See the client to server area on remote events.
So first, create a new remote event in replicated storage using the plus button on hover, and click remote event. Name it what you want. In this code I am going to assume it is named FirstWave There are picture instructions on the webpage
Then use this as your gui code:
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Get replicated storage local firstWaveEvent = ReplicatedStorage:WaitForChild("FirstWave") -- Find the remote event TriggerCount = 0 local function TriggerCountAdd() TriggerCount = TriggerCount + 1 print(TriggerCount) end script.Parent.MouseButton1Click:Connect(TriggerCountAdd) -- See below about this if TriggerCount == 3 then firstWaveEvent:FireServer() -- Signal the server end
I changed how you called the function with the clicks, because before you made an anonymous function, and in that function you called your TriggerCountAdd() Now it is just calling the function. If it stops working, put it back again ig.
Then your server code should look like this:
local ReplicatedStorage = game:GetService("ReplicatedStorage") local firstWaveEvent = ReplicatedStorage:WaitForChild("FirstWave") local function destroyBarrier() -- Put your destroying in a function workspace.BarrierCrush1:Destroy() end firstWaveEvent.OnServerEvent:Connect(destroyBarrier) -- Event calls the function when the remote event is send by gui
Hopefully this will make it work, let me know if it doesn't. Sorry for the late reply!