local tiger = script.Parent
local humanoid = tiger:WaitForChild("Humanoid")
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(player)
print(0)
if player then
print(1)
local target = player.Character
local distance = (tiger.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance <= 8 and target and not tiger then
print(2)
tiger.Head.AttackSound:Play()
local playerDeath = game.ReplicatedStorage:WaitForChild("playerdeath")
local player = game.Players:GetPlayerFromCharacter(target)
playerDeath:FireClient(player,tiger)
local attackAnim = humanoid:LoadAnimation(script.Attack)
attackAnim:Play()
attackAnim.Stopped:Wait()
target.Humanoid.Health = 0
end
end
end)
Local Script:
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
print("Attacked")
game.ReplicatedStorage.Attack:FireServer()
end
end)
Your code says, if the distance is less than or equal to 8 AND target exists AND tiger does not exist THEN do stuff. But tiger will ALWAYS exist as long as this script is running because tiger is the parent of the script. If there is no parent to your script then your script does not exist in the game.
Remove your check for tiger and it will run as expected.
when you fire a remote event to the server, the player is always going to be the client who fired the event. therefore, you’re simply checking if MyPlayer is not equal to MyPlayer. I would recommend looping through all the players.
local tiger = script.Parent
local humanoid = tiger:WaitForChild("Humanoid")
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(player)
print(0)
for i,player in pairs(game.Players:GetChildren()) do
print(1)
local target = player.Character
local distance = (tiger.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance <= 8 and target then
print(2)
tiger.Head.AttackSound:Play()
local playerDeath = game.ReplicatedStorage:WaitForChild("playerdeath")
local player = game.Players:GetPlayerFromCharacter(target)
playerDeath:FireClient(player,tiger)
local attackAnim = humanoid:LoadAnimation(script.Attack)
attackAnim:Play()
attackAnim.Stopped:Wait()
target.Humanoid.Health = 0
end
end
end)
local tiger = script.Parent
local humanoid = tiger:WaitForChild("Humanoid")
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(player)
print(0)
for i,v in pairs(game.Players:GetChildren()) do
print(1)
local target = player.Character
local distance = (tiger.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
if distance <= 8 and target then
print(2)
tiger.Head.AttackSound:Play()
local playerDeath = game.ReplicatedStorage:WaitForChild("playerdeath")
local player = game.Players:GetPlayerFromCharacter(target)
playerDeath:FireClient(player,tiger)
local attackAnim = humanoid:LoadAnimation(script.Attack)
attackAnim:Play()
attackAnim.Stopped:Wait()
target.Humanoid.Health = 0
end
end
end)
hold on, can the player attack the tiger? or is it the tiger attacking the player? but dont do that, replace v with player, and replace the player referenced in the onserverevent with nothing. (you should also use GetPlayers() instad)