I am trying to make it so that when some values are met, a remove event will fire which will, in turn, enable a GUI
This code isn’t working, it prints nothing
First Script Normal Script
local rs = game:GetService("ReplicatedStorage")
local Finished = rs:WaitForChild("FinishedRemote")
local player = game.Players.LocalPlayer
local B = script.Parent.Bodies.Value
local H = script.Parent.Hostages.Value
local W = script.Parent.Weapons.Value
while wait() do
if B >= 8 and H >= 1 and W >= 1 then
print("ea")
Finished:FireAllClients()
else
end
end
Second Script Local Script
local rs = game:GetService("ReplicatedStorage")
local Finished = rs:WaitForChild("FinishedRemote")
Finished.OnClientEvent:Connect(function()
print("eg1a")
script.Parent.Enabled = true
end)
Because if you do the second thing the variable will store the current value only
Try to fire the remote event without the if statement
Second of all, no, localplayer is not the issue since it returns empty in the server, it does not error and you are not using it, but it’s useless
Third of all, I can see that your script and valuebases are probably inside a character, am I right? If that’s true, please stop doing this. StarterCharacterScripts, or relying on character children is not good and is bad practice.
I think I know your issue, the serverscript loads first than the localscript so when you define the event in the localscript, it does not receive it because it was fired before, can you test this in the server script?
while task.wait(3) do
remote:FireAllClients()
end
Here is your final fixed serverscript:
local rs = game:GetService("ReplicatedStorage")
local FinishedRemote = rs:WaitForChild("FinishedRemote")
local B = script.Parent.Bodies
local H = script.Parent.Hostages
local W = script.Parent.Weapons
while task.wait() do
if B.Value >= 8 and H.Value >= 1 and W.Value >= 1 then
Finished:FireAllClients()
end
end