If Statement is ignored in a OnClientEvent local script

Hello!
I’m trying to make a jumpscare system for my game.
The entire game works fine besides the jumpscare local script.

The whole local scripts works fine, but the if statement gets ignored.

Local Script

game.ReplicatedStorage.jumpscare.OnClientEvent:Connect(function(plr, js)
	print("onclientevent fired")
	local randomtext = math.random(1,5)
	if randomtext == 1 then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext.Text = "Ouch."
	elseif randomtext == 2 then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext.Text = "Yikes."
	elseif randomtext == 3 then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext.Text = "That must've hurt..."
	elseif randomtext == 4 then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext.Text = "Everyone makes mistakes."
	elseif randomtext == 5 then
		game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext.Text = "You'll get better eventually."
	end
	print("random text chosen")
	if js == 1 then
		print("local jumpscare 1")
		local jumpscareanim = workspace.jumpscarebox.Monster.Humanoid:LoadAnimation(workspace.jumpscarebox.Monster.jumpscare)
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		workspace.CurrentCamera.CFrame = workspace.jumpscarebox.jumpscarecam.CFrame
		jumpscareanim:Play()
		wait(0.1)
		workspace.jumpscarebox.jumpscaresound:Play()
		wait(0.7)
		game.Lighting.Blind.Enabled = true
		wait(2)
		game.TweenService:Create(game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext, TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {TextTransparency = 0}):Play()
		wait(4)
		game.TweenService:Create(game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext, TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		wait(4)
		workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		game.Lighting.Blind.Enabled = false
		print("done")
	elseif js == 2 then
		print("local jumpscare 2")
		local jumpscareanim = workspace.jumpscarebox.Monster.Humanoid:LoadAnimation(workspace.jumpscarebox.Monster.jumpscare2)
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
		workspace.CurrentCamera.CFrame = workspace.jumpscarebox.jumpscarecam.CFrame
		jumpscareanim:Play()
		game.TweenService:Create(workspace.CurrentCamera, TweenInfo.new(0.20, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {CFrame = workspace.jumpscarebox.jumpscarecam2.CFrame}):Play()
		wait(.20)
		workspace.jumpscarebox.punchsfx:Play()
		wait(.63)
		workspace.jumpscarebox.jumpscaresound2:Play()
		wait(1.15)
		game.Lighting.Blind.Enabled = true
		wait(2)
		game.TweenService:Create(game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext, TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {TextTransparency = 0}):Play()
		wait(4)
		game.TweenService:Create(game.Players.LocalPlayer.PlayerGui.ScreenGui.deadtext, TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {TextTransparency = 1}):Play()
		wait(4)
		workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		game.Lighting.Blind.Enabled = false
		print("done")
	end
	print("onclientevent done")
end)

The local script prints “onclientevent fired”, “random text chosen” and “onclientevent done”, but the if statements are completely ignored like they aren’t even in the script.

Server script

local db = false
script.Parent.Touched:Connect(function(hit)
	if db == false then
		if hit.Parent:FindFirstChild("Humanoid") then
			if not hit.Parent:FindFirstChild("NPC") then
				if hit.Parent.Humanoid.Health > 0 then
					local choosejumpscare = math.random(1,2)
					if choosejumpscare == 1 then
						db = true
						print("jumpscared1")
						local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
						game.ReplicatedStorage.jumpscare:FireClient(plr, choosejumpscare)
						wait(0.85)
						hit.Parent.Humanoid:TakeDamage(100)
						wait(1)
						db = false
					elseif choosejumpscare == 2 then
						db = true
						print("jumpscared2")
						local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
						game.ReplicatedStorage.jumpscare:FireClient(plr, choosejumpscare)
						wait(1.18)
						hit.Parent.Humanoid:TakeDamage(100)
						wait(1)
						db = false						
					end
				end	
			end
		end
	end
end)

The Player argument isn’t passed in an OnClientEvent only on an OnServerEvent

1 Like

Oh. I didn’t know that. Thank you!

1 Like