I have been trying to fix this for 3 days now and it is making no sense. I have a hixbox put on each player at the start of the game. The hitbox has a script in it that can be run by setting the DamageIntake Bool value within the script to true which is detected by by a changed event.
I have also put a string value within the script that is called CurrentPlayer and has the name of the current model that the hitbox is inside. For some reason even though the currentPlayer value is set to the correct player(I checked them in a running 2 player game) , one player is able to hit the other but the second player cannot hit the first. I have printed the player names at the start of the script to ensure it is the right player but it still detects the wrong player when I say
game.Workspace:FindFirstChild(script.CurrentPlayer.Value).Humanoid.Health -= script.DamageAmount.Value
This makes no sense as it seems like the string value somehow has 2 values at once. I have check and changed the code over the last 3 days as much as possible with no luck. Someone save me please.
Here is the full code : `
--Welds the hitbox to the player
while true do
wait()
if script.Parent.Parent.Parent:FindFirstChild("Humanoid") then
script.CurrentPlayer.Value = script.Parent.Parent.Parent.Name
print(script.CurrentPlayer.Value)
local rootPart = game.Workspace:FindFirstChild(script.CurrentPlayer.Value).HumanoidRootPart
local weld = Instance.new("Weld",rootPart)
weld.Part0 = rootPart
weld.part1 = script.Parent
weld.C1 *= CFrame.new(0,.5,0)
break
end
end
print(script.CurrentPlayer.Value.."again")
--Specifications
local IFramesTime = 0.1
--Character features
local hitBox = script.Parent
local damageIntake = script.hit
local event = game.ReplicatedStorage.RemoteEvents.BDD
--Character action states
local IsBlocking = false
local blockFrames = 0
--Asks client for character actions
damageIntake.Changed:Connect(function(change)
print(script.Parent.Parent.Parent.Name.." script running")
--Ensure the damage change is the player getting hit and not the IFrames vanishing
if change == true then
event:InvokeClient(game.Players:FindFirstChild(script.CurrentPlayer.Value),"Blocking")
wait(0.1)
damageIntake.Value = false
end
end)
--Client returns values and the attack is run
event.OnServerInvoke = function(plr,value,blockTime,defenenceType)
if defenenceType == "Blocking" then
blockFrames = blockTime
IsBlocking = value
end
if IsBlocking == false then
task.wait()
game.Workspace:FindFirstChild(script.CurrentPlayer.Value).Humanoid.Health -= script.DamageAmount.Value
print(game.Workspace:FindFirstChild(script.CurrentPlayer.Value).Name.."got hit")
if script.Ragdoll.Value == true then
local ragdollScript = require(game.ServerScriptService.ServerScripts.Ragdoll)
script.Ragdoll.Value = false
ragdollScript.Start(game.Workspace:FindFirstChild(script.CurrentPlayer.Value))
wait(script.RagdollTime.Value)
ragdollScript.Stop(game.Workspace:FindFirstChild(script.CurrentPlayer.Value),100,16)
script.RagdollTime.Value = 0
end
if script.KnockBackPower.Value > 0 then
local velocity = Instance.new("BodyVelocity",game.Workspace:FindFirstChild(script.CurrentPlayer.Value).HumanoidRootPart)
velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
velocity.Velocity = game.Workspace:FindFirstChild(script.PlayerWhoHit.Value).HumanoidRootPart.CFrame.LookVector * script.KnockBackPower.Value
wait(script.KnockBackTime.Value)
velocity:Destroy()
end
end
end