What is causing my script to not work

Main script

local bool = workspace.CharaWon
local counter = workspace.TRUEINSANITYHITS.Value
local counter2 = workspace.TRUEINSANITYACTIVE.Value
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.TRUEINSANITYDEATH

while true do
	if bool.Value == true then
		local sans = players:FindFirstChildOfClass("Player")
		if sans.TeamColor == BrickColor.new("Navy blue") then
			for _, backpackItems in pairs (sans.Backpack:GetChildren()) do
				backpackItems:Destroy()
			end
			else
		end
		task.wait(5)
		for i = 1,999999999999999 do
			for _, player in pairs (players:GetChildren()) do
				player:Kick("Chara has won.")
				task.wait(0.01)
			end
		end
	end

--This is the more important part I want to focus on for, which is the reason why I'm asking for help.--

	remoteEvent.OnServerEvent:Connect(function()
		print("READY.")
		if bool.Value == false and counter >= 15 and counter2 == true then
			print("RECEIVED")
			local HIM = workspace["HIM V2"]
			local sound = workspace.omega_flowey
			local sans = players:FindFirstChildOfClass("Player")
			HIM:Destroy()
			sound:Play()
			task.wait(5)
			print("STAGE 2")
			if sans.TeamColor == BrickColor.new("Navy blue") then
				for _, backpackItems in pairs (sans.Backpack:GetChildren()) do
					backpackItems:Destroy()
				end
			else
			end
			print("STAGE 3")
			for i = 1,999999999999999 do
				for _, player in pairs (players:GetChildren()) do
					player:Kick("HAHAHHAHAHAHAHHAHAHHAHAHHAHAHAHHAHA")
					task.wait(0.01)
				end
			end
elseif counter <= 14 then
			print("FALSE SOMEHOW")
			task.wait(0.01)
		end
	end)
		
		
		
	--TRUEBARRIERDEATH
	
	
	task.wait(0.5)
end

The part I want to focus on is this part,

remoteEvent.OnServerEvent:Connect(function()
		print("READY.")
		if bool.Value == false and counter >= 15 and counter2 == true then
			print("RECEIVED")
			local HIM = workspace["HIM V2"]
			local sound = workspace.omega_flowey
			local sans = players:FindFirstChildOfClass("Player")
			HIM:Destroy()
			sound:Play()
			task.wait(5)
			print("STAGE 2")
			if sans.TeamColor == BrickColor.new("Navy blue") then
				for _, backpackItems in pairs (sans.Backpack:GetChildren()) do
					backpackItems:Destroy()
				end
			else
			end
			print("STAGE 3")
			for i = 1,999999999999999 do
				for _, player in pairs (players:GetChildren()) do
					player:Kick("HAHAHHAHAHAHAHHAHAHHAHAHHAHAHAHHAHA")
					task.wait(0.01)
				end
			end
elseif counter <= 14 then
			print("FALSE SOMEHOW")
			task.wait(0.01)
		end
	end)

Allow me to explain.

The script receives the remoteEvent, which then does the events. However, even after all the conditions have met, the segment only prints print("READY.") and keeps printing the elseif counter <= 14 then statement when ironically, the counter is above 15 when the remoteEvent is supposed to happen and I do not know what is the issue with the script. I’ve also checked TRUEINSANITYACTIVE.Value and CharaWon and TRUEINSANITYACTIVE.Value prints true but doesn’t seem to be checked off (what I mean by is having the blue box and being enabled on the Value, vice versa for CharaWon. I do not know what’s causing this problem and I do not want to remove the if statements or else someone may intentionally exploit the remoteEvent to instantly fire off the events and I do not know why at the same time it’s bugging. I really need the help. I do not know what’s causing this issue. I’d greatly appreciate it if I received help. I’ve tried countless times to solve the problem, and I can’t figure out why its not working.

1 Like

tip people like us can help you better if you let us know in the script what is going on because some scripts may be a mess and we do not know what to help you with

and i think your issue is because your script is running into a loop here is a script that might or might not idk solve your issue ig

local bool = workspace.CharaWon
local counter = workspace.TRUEINSANITYHITS.Value
local counter2 = workspace.TRUEINSANITYACTIVE.Value
local players = game:GetService(“Players”)
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local remoteEvent = replicatedStorage.TRUEINSANITYDEATH

while true do
if bool.Value == true then
local sans = players:FindFirstChildOfClass(“Player”)
if sans.TeamColor == BrickColor.new(“Navy blue”) then
for _, backpackItems in pairs(sans.Backpack:GetChildren()) do
backpackItems:Destroy()
end
end

	task.wait(5)

	for _, player in pairs(players:GetChildren()) do
		player:Kick("Chara has won.")
	end
end

remoteEvent.OnServerEvent:Connect(function()
	print("READY.")
	if bool.Value == false and counter >= 15 and counter2 == true then
		print("RECEIVED")
		local HIM = workspace["HIM V2"]
		local sound = workspace.omega_flowey
		local sans = players:FindFirstChildOfClass("Player")
		HIM:Destroy()
		sound:Play()
		task.wait(5)
		print("STAGE 2")
		if sans.TeamColor == BrickColor.new("Navy blue") then
			for _, backpackItems in pairs(sans.Backpack:GetChildren()) do
				backpackItems:Destroy()
			end
		end
		print("STAGE 3")
		for _, player in pairs(players:GetChildren()) do
			player:Kick("HAHAHHAHAHAHAHHAHAHHAHAHHAHAHAHHAHA")
			task.wait(0.01)
		end
	elseif counter <= 14 then
		print("FALSE SOMEHOW")
		task.wait(0.01)
	end
end)

-- TRUEBARRIERDEATH

task.wait(0.5)

end

2 Likes

Are you changing the bool value from the client?

The bool value is being changed from a button from a localScript that fires off a remoteEvent to one of the main scripts in ServerScriptService, which after it fully receives under certain conditions will turn the boolean value to true. Should I send the script that does it?

If you change a bool value on a local script, only the client will see the change. You’ll have to handle the bool value on server-side.

i hope this helps

remoteEvent.OnServerEvent:Connect(function()
	print("READY.")
	if bool.Value == false and counter <= 15 and counter2 == true then -- Previously you had counter >= 15, stating it will only fire if all the other statements meet and counter is above 15
		print("RECEIVED")
		local HIM = workspace["HIM V2"]
		local sound = workspace.omega_flowey
		local sans = players:FindFirstChildOfClass("Player")
		HIM:Destroy()
		sound:Play()
		task.wait(5)
		print("STAGE 2")
		if sans.TeamColor == BrickColor.new("Navy blue") then
			for _, backpackItems in pairs (sans.Backpack:GetChildren()) do
				backpackItems:Destroy()
			end
		else
		end
		print("STAGE 3")
		for i = 1,999999999999999 do
			for _, player in pairs (players:GetChildren()) do
				player:Kick("HAHAHHAHAHAHAHHAHAHHAHAHHAHAHAHHAHA")
				task.wait(0.01)
			end
		end
	elseif counter <= 14 then
		print("FALSE SOMEHOW")
		task.wait(0.01)
	end
end)

this isn’t the problem he’s facing, and this isn’t a good work-around

I’m not changing the bool on the localScript. I’ll send the script of the button.

local teamColor = BrickColor.new("Navy blue")

function UpdateUI()
	local Player = game.Players.LocalPlayer
	local PlayerId = Player.UserId
	local PGUI = Player:WaitForChild("PlayerGui") 
	local whitelist = require(PGUI.TrueInsanityGui.WhitelistScript)
	if Player.TeamColor == teamColor and whitelist[PlayerId] then 
		PGUI.TrueInsanityGui.Enabled = true
		print("APPEAR")
	else
		PGUI.TrueInsanityGui.Enabled = false 
		print("FALSE")
	end 
end  UpdateUI() --Added this here so it doesn't look messy in the rest of the script but still runs the function after its created for the first time.

game.Players.LocalPlayer:GetPropertyChangedSignal("TeamColor"):Connect(UpdateUI)

Heres the script that receives the remoteEvent.

--SERVICES
local lighting = game:GetService("Lighting")
local serverStorage = game:GetService("ServerStorage")
local replicatedStorage = game:GetService("ReplicatedStorage")
local starterGui = game:GetService("StarterGui")
local serverScriptService = game:GetService("ServerScriptService")
local musicGui = starterGui.MusicGui
local otherSansGui = starterGui.OtherSansGui
local trueInsanitySansGui = starterGui.TrueInsanityGui
local remoteEvent1 = replicatedStorage.AsgoreEvent
local remoteEvent2 = replicatedStorage.ReaperMode
local remoteEvent3 = replicatedStorage.TRUEINSANITYMODE
local mainEvent = replicatedStorage.GuiChange
local badgeService = game:GetService("BadgeService")
local badge = 1717683932853397
local whitelist = require(otherSansGui.Frame.ReaperSansButton.WhitelistScript)
local whitelist2 = require(trueInsanitySansGui.WhitelistScript)
--SOUNDS
local music = workspace["Megalovania Tenskitsune Remix"]
local music2 = workspace["[Undertale] Last Stand"]
local music3 = workspace["Bensley - Vex"]
local music4 = workspace["Lethalovania"]
local sound1 = workspace["Freddy Krueger Laugh (With Echo)"]
--VALUES
local bool1 = workspace.SansEvent.Value
local bool2 = workspace.TRUEINSANITYACTIVE.Value
--MODELS
local OGSans = workspace.OGSans
local HALL = workspace["judgement hall"]
local SansNAsgore = serverStorage.AsgoreNSansMap
local ReaperSansMap = serverStorage.ReaperSansMap
local TrueInsanity = serverStorage.TrueInsanityMap
local endgame = workspace.Endgame
--ETC
local sky = serverStorage["Hell V2/Nightmare Sector Sky"]
--PLAYERS
local players = game:GetService("Players")
local teams = game:GetService("Teams")
local team = teams.Sans.TeamColor
local normalFolder = serverStorage.SansNAsgore
local normalFolder2 = serverStorage.ReaperSans
local normalFolder3 = serverStorage.TrueInsanitySans
team = BrickColor.new("Navy blue")


local function TrueInsanityMode(player)
	bool2 = true
	local sans = players:FindFirstChildOfClass("Player")
	local chara = players:FindFirstChildOfClass("Player")
	local backpack = sans.Backpack
	local SANS = TrueInsanity["HIM V2"]
	local map = TrueInsanity.Map
	local PGUI = sans.PlayerGui
	local SGUI = PGUI.MusicGui
	local MGUI = SGUI.Frame
	local POtherSansGui = PGUI.OtherSansGui
	--ATTACKS
	local TRUEAXESMASH = normalFolder3["TRUE AXE SMASH"]
	local AUCODEDELETION = normalFolder3["AU CODE DELETION."]
	local BLASTERS = normalFolder3["TRUE GASTER BLASTERS"]
	if bool2 == true then
		if sans.TeamColor == BrickColor.new("Navy blue") then
			local character = sans.Character
			if character:FindFirstChildWhichIsA("Tool") then -- IF PLAYER IS ABUSING A BUG, DESTROY CURRENT HOTBAR REGARDLESS
				character:FindFirstChildWhichIsA("Tool"):Destroy()
			end
			for _, backpackItems in pairs (sans.Backpack:GetChildren()) do
				backpackItems:Destroy()
			end
		else
			print("What else is there?")
		end
		if chara.TeamColor == BrickColor.new("Bright red") then
			local character = chara.Character
			if character:FindFirstChildWhichIsA("Tool") then -- IF PLAYER IS ABUSING A BUG, DESTROY CURRENT HOTBAR REGARDLESS
				character:FindFirstChildWhichIsA("Tool"):Destroy()
			end
			for _, backpackItems in pairs (chara.Backpack:GetChildren()) do
				backpackItems:Destroy()
			end
		else
			print("What else is there?")
		end
		if backpack then
			if player.TeamColor == BrickColor.new("Navy blue") and whitelist2[player.UserId] then
				TRUEAXESMASH:Clone().Parent = backpack
				AUCODEDELETION:Clone().Parent = backpack
				BLASTERS:Clone().Parent = backpack
				print("PLAYER HAS RECEIVED TOOLS.")
			end
		end
		for _, player in pairs (players:GetChildren()) do
			local PlayerGUI = player:WaitForChild("PlayerGui")
			PlayerGUI.MusicGui.Frame.Theme2.Text = "Lethalovania"
			PlayerGUI.MusicGui.Frame.Artist.Text = "SharaX"
			print("COMPLETE")
		end
		serverStorage["Chara Knife"]:Destroy()
		sans.CameraMaxZoomDistance = 100000
		MGUI.Theme2.Text = "Lethalovania"
		MGUI.Artist.Text = "SharaX"
		musicGui.Frame.Theme2.Text = "Lethalovania"
		musicGui.Frame.Artist.Text = "SharaX"
		sky:Clone().Parent = lighting
		otherSansGui:Destroy()
		POtherSansGui:Destroy()
		HALL:Destroy()
		map:Clone()
		map.Parent = workspace
		OGSans:Destroy()
		SANS:Clone()
		SANS.Parent = workspace
		music:Stop()
		music4:Play()
		music4.Looped = true
		endgame:Destroy()
		local TRUEBARRIERSPAWNS = workspace.TrueBarrierSpawns:GetChildren()
		for index, platform in TRUEBARRIERSPAWNS do
			platform.Enabled = true
		end
		workspace.CharaSpawn.Enabled = false
		serverScriptService.TRUEINSANITYFIGHTBUTTONS.Enabled = true
		print(bool1)
		print(bool2)
	elseif player.TeamColor == BrickColor.new("Navy blue") and not whitelist2[player.UserId] then
		sans:Kick("CRAZY EXPLOITING.")
	end
end

remoteEvent1.OnServerEvent:Connect(AsgoreMode)
remoteEvent2.OnServerEvent:Connect(ReaperMode)
---MAIN EVENT---
remoteEvent3.OnServerEvent:Connect(TrueInsanityMode)

This is a gigantic shortened amount of code just for the post. The main thing that’s important here is the (TrueInsanityMode) event/function. The serverscript does work, it’s just that I shortened it heavily.

When I printed out both booleans and checked in workspace on server view, the main boolean TRUEINSANITYACTIVE.Value did not appear to have it’s Value box checked off.

What does the console print when the remote event fires? (On the main script on the part you highlighted.)

What part are you referring to?

remoteEvent.OnServerEvent:Connect(function()
	print("READY.")
	if bool.Value == false and counter <= 15 and counter2 == true then -- Previously you had counter >= 15, stating it will only fire if all the other statements meet and counter is above 15
		print("RECEIVED")
		local HIM = workspace["HIM V2"]
		local sound = workspace.omega_flowey
		local sans = players:FindFirstChildOfClass("Player")
		HIM:Destroy()
		sound:Play()
		task.wait(5)
		print("STAGE 2")
		if sans.TeamColor == BrickColor.new("Navy blue") then
			for _, backpackItems in pairs (sans.Backpack:GetChildren()) do
				backpackItems:Destroy()
			end
		else
		end
		print("STAGE 3")
		for i = 1,999999999999999 do
			for _, player in pairs (players:GetChildren()) do
				player:Kick("HAHAHHAHAHAHAHHAHAHHAHAHHAHAHAHHAHA")
				task.wait(0.01)
			end
		end
	elseif counter <= 14 then
		print("FALSE SOMEHOW")
		task.wait(0.01)
	end
end)

The script prints both print("READY.") and print("FALSE SOMEHOW"), when ironically the counter is above 15 and it’s not supposed to print that. That is there for debugging.

Also, the counter is not supposed to be counter <= 15. That is not what I want my script to do.

can you print the bool, counter, and counter 2?

For which script do I print it in?


Right here, put it after “print(“READY.”)”

	print("READY.")
        print(bool.Value, counter, counter2)
	if bool.Value == false and counter <= 15 and counter2 == true then 

Oh,

if bool.Value == false and counter >= 15 and counter2 == true then

is bool supposed to be false? You stated that CharaWon, or bool prints true, correct?

Actually, I see your problem.


Your referencing the value’s beforehand. Reference them on the same script.

Alright, so I printed them in.

12:04:43.971  CharaWon  -  Server - WinScript:43
  12:04:43.994  0  -  Server - WinScript:44
  12:04:43.995  false  -  Server - WinScript:45
local bool = workspace.CharaWon
local counter = workspace.TRUEINSANITYHITS
local counter2 = workspace.TRUEINSANITYACTIVE
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage.TRUEINSANITYDEATH

while true do
	if bool.Value == true then
		local sans = players:FindFirstChildOfClass("Player")
		if sans.TeamColor == BrickColor.new("Navy blue") then
			for _, backpackItems in pairs (sans.Backpack:GetChildren()) do
				backpackItems:Destroy()
			end
		else
		end
		task.wait(5)
		for i = 1,999999999999999 do
			for _, player in pairs (players:GetChildren()) do
				player:Kick("Chara has won.")
				task.wait(0.01)
			end
		end
	end

	--This is the more important part I want to focus on for, which is the reason why I'm asking for help.--

	remoteEvent.OnServerEvent:Connect(function()
		print("READY.")
		if bool.Value == false and counter.Value >= 15 and counter2.Value == true then
			print("RECEIVED")
			local HIM = workspace["HIM V2"]
			local sound = workspace.omega_flowey
			local sans = players:FindFirstChildOfClass("Player")
			HIM:Destroy()
			sound:Play()
			task.wait(5)
			print("STAGE 2")
			if sans.TeamColor == BrickColor.new("Navy blue") then
				for _, backpackItems in pairs (sans.Backpack:GetChildren()) do
					backpackItems:Destroy()
				end
			else
			end
			print("STAGE 3")
			for i = 1,999999999999999 do
				for _, player in pairs (players:GetChildren()) do
					player:Kick("HAHAHHAHAHAHAHHAHAHHAHAHHAHAHAHHAHA")
					task.wait(0.01)
				end
			end
		elseif counter.Value <= 14 then
			print("FALSE SOMEHOW")
			task.wait(0.01)
		end
	end)



	--TRUEBARRIERDEATH


	task.wait(0.5)
end

hope this fixes