It only prints 1!

It only prints 1 in the server script!

Server Script:

local tiger = script.Parent
local humanoid = tiger:WaitForChild("Humanoid")
local debounce = true

game.ReplicatedStorage.TraitorAttack.OnServerEvent:Connect(function()
	print(0)
	for i,player in pairs(game.Players:GetPlayers()) do
		print(1)
		local target = player.Character
		local distance = (tiger.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
		if distance <= 8  and target and target ~= tiger and humanoid.WalkSpeed ~= 0 and debounce == true then
			debounce = false
			print(2)
			tiger.Head.AttackSound:Play()
			local playerDeath = game.ReplicatedStorage:WaitForChild("playerdeath")
			local player = game.Players:GetPlayerFromCharacter(target)
			local tigerplayer = game.Players:GetPlayerFromCharacter(tiger)
			playerDeath:FireClient(player,tiger)
			local attackAnim = humanoid:LoadAnimation(script.Attack)
			attackAnim:Play()
			attackAnim.Stopped:Wait()
			target.Humanoid.Health = 0
			tigerplayer.leaderstats.Meat.Value += 1
			wait(10)
			debounce = true
		end
	end
end)

Local Script:

local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local canAttack = script.Parent:WaitForChild("CanAttack").Value
canAttack = false

game.ReplicatedStorage.RoundInfo.Status:GetPropertyChangedSignal("Value"):Connect(function()
	if game.ReplicatedStorage.RoundInfo.Status.Value == "Intermission" or game.ReplicatedStorage.RoundInfo.Status.Value == "" then
		canAttack = false
	end
end)

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q or input.KeyCode == Enum.KeyCode.ButtonY or input.UserInputType == Enum.UserInputType.Touch  then
		if canAttack == true and player.Character.Name == "Traitor" then
			print("Attacked")
			game.ReplicatedStorage.TraitorAttack:FireServer()
		end
	elseif canAttack == false and game.ReplicatedStorage.RoundInfo.Status.Value == "Game" and player.Character.Name == "Traitor" then
		print("Cannotattack")
		wait(60)
		canAttack = true
	end
end)


2 Likes

The easiest way to check to see if your parameters are what you expect is to print them before the if statements:
Printing when a function works (like print("Attacked")) or something like that only tells you when the if statement meets the parameters, but doesn’t tell you why it doesn’t meet them.
Try things like:

        print("distance = ", distance, "    target = ", target, "    humanoid.Walkspeed = ", humanoid.Walkspeed, "    debounce = ", debounce)
		if distance <= 8  and target and target ~= tiger and humanoid.WalkSpeed ~= 0 and debounce == true then

Once you find out which parameter (variable) isn’t what you expect then you can go to the section of script that sets that parameter and troubleshoot there.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.