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

If a variable reaches 3, a trigger is made in RepStor, which destroys a part. Why doesn't this work?

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

1 answer

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!

3 comments

0

Here's what I need to accomplish:

0

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?

0

Ok I couldn't post another answer, so I edited my existing one. Hope it helps!

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