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")
local firstWaveEvent = ReplicatedStorage:WaitForChild("FirstWave")
TriggerCount = 0
local function TriggerCountAdd()
TriggerCount = TriggerCount + 1
print(TriggerCount)
end
script.Parent.MouseButton1Click:Connect(TriggerCountAdd)
if TriggerCount == 3 then
firstWaveEvent:FireServer()
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()
workspace.BarrierCrush1:Destroy()
end
firstWaveEvent.OnServerEvent:Connect(destroyBarrier)
Hopefully this will make it work, let me know if it doesn't. Sorry for the late reply!
3 comments
Here's what I need to accomplish:
Here's what I need to accomplish: There is an invisible button that covers the screen, if clicked, adds 1 to a value, in this case, is 0. When that value reaches three, I used an if message to add a trigger in ReplicatedStorage. When they detect the trigger, they will destroy a part. What possibly do I change to make this happen?
Ok I couldn't post another answer, so I edited my existing one. Hope it helps!