So basically I have an Fire ball script witch creates an clone from the Replicated Storage and tweens it , but the damage doesn’t work , i tried to print the name of the player that was hit but it doesn’t print anything
I have an remote event in replicated storage called "Fire"
Local Script:
local uis = game:GetService("UserInputService")
local CoolDown = .6
can = true
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E and can then
can = false
game.ReplicatedStorage.Fire:FireServer()
wait(CoolDown)
can = true
end
end)
Script:
local re = game.ReplicatedStorage.Fire
local fireball = game.ReplicatedStorage.FireBall
local ts = game:GetService("TweenService")
re.OnServerEvent:Connect(function(plr)
local clone = fireball:Clone()
clone.Position = plr.Character.PrimaryPart.CFrame:PointToWorldSpace(Vector3.new(0,0,-5))
local tweeninfo = TweenInfo.new(.6,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local tween = ts:Create(clone,tweeninfo,{Position = plr.Character.PrimaryPart.CFrame:PointToWorldSpace(Vector3.new(0,0,-60)) })
tween:Play()
clone.Parent = game.Workspace
clone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
tween:Cancel()
clone:Destroy()
hit.Parent.Humanoid:TakeDamage(30)
end
end)
wait(.6)
tween:Cancel()
clone:Destroy()
end)
Are you testing with 2 people? The remote checks to make sure that the character that was hits name does not equal the one who fired the remote, so if your testing it on yourself that won’t work
If you are testing it with 2 people, I don’t really know where it’s going wrong, but you could use BasePart:GetTouchingParts() if you really can’t figure out how to get the touched event to work.
Actually, disregard my first post, I think the reason it isn’t working is because you connect the event after you tween the ball, and tweening yields (if i remember correctly). So you can connect the .Touched event before you play the tween and that should work
You may also want to parent the ball to the workspace before you start the tween, I don’t know if that will change much anyways
local re = game.ReplicatedStorage.Fire
local fireball = game.ReplicatedStorage.FireBall
local ts = game:GetService("TweenService")
re.OnServerEvent:Connect(function(plr)
local clone = fireball:Clone()
clone.Position = plr.Character.PrimaryPart.CFrame:PointToWorldSpace(Vector3.new(0,0,-5))
local tweeninfo = TweenInfo.new(.6,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local tween = ts:Create(clone,tweeninfo,{Position = plr.Character.PrimaryPart.CFrame:PointToWorldSpace(Vector3.new(0,0,-60)) })
clone.Parent = game.Workspace
tween:Play()
clone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
tween:Cancel()
clone:Destroy()
hit.Parent.Humanoid:TakeDamage(30)
end
end)
wait(.6)
tween:Cancel()
clone:Destroy()
end)
local re = game.ReplicatedStorage.Fire
local fireball = game.ReplicatedStorage.FireBall
local ts = game:GetService("TweenService")
re.OnServerEvent:Connect(function(plr)
local clone = fireball:Clone()
clone.Position = plr.Character.PrimaryPart.CFrame:PointToWorldSpace(Vector3.new(0,0,-5))
local tweeninfo = TweenInfo.new(.6,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local tween = ts:Create(clone,tweeninfo,{Position = plr.Character.PrimaryPart.CFrame:PointToWorldSpace(Vector3.new(0,0,-60)) })
clone.Parent = game.Workspace
tween:Play()
clone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name ~= plr.Name then
tween:Cancel()
clone:Destroy()
hit.Parent.Humanoid.Health -= 30
end
end)
wait(.6)
tween:Cancel()
clone:Destroy()
end)
local connection;
connection = clone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') and hit.Parent.Name ~= plr.Name then
hit.Parent.Humanoid:TakeDamage(30)
if connection ~= nil then connection:Disconnect()
tween:Cancel()
clone:Destroy()
end
end)
task.wait(.6)
if connection ~= nil then connection:Disconnect()
tween:Cancel()
clone:Destroy()
Can you print out hit in the start of the touched event to see if it’s at least getting what it hit?
My only guess as to why it’s not working if it does print out is that it’s hitting an accessory, as hit.Parent in that case would give an accessory.
Maybe try getting the humanoid via FindFirstAncestorOfClass("Model") instead of hit.Parent
local character = hit:FindFirstAncestorOfClass("Model")
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
-- Code to do the damaging
Wait… what if the conditions haven’t been met? I think it would be better if you have added another condition to see if the hit.Parent:IsA("Model").
Something like this:
clone.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and hit.Parent.Name ~= plr.Name and hit.Parent:IsA("Model") then
tween:Cancel()
clone:Destroy()
hit.Parent.Humanoid.Health -= 30
end
end)
I think I know why. Let’s analyze what @EmbatTheHybrid had said earlier:
Basically referring to what they said, the problem would be that the hit’s Parent is an accessory and not a model. You know, accessories can have a bigger hitbox than the character itself; hence this error we get.
So to check to make sure that it’s a model and not anything else, we can just check to see if hit.Parent:IsA("Model") like what @EmbatTheHybrid did.
(To be honest, I think you should’ve given them the solution since they did just find it faster than what I did.)
I think you read my code wrong, I didn’t use IsA, I used FindFirstAncestorOfClass and FindFirstChildOfClass to ensure that anything that hits the character, even the accessories, will still damage the player.
What confuses me is how your implementation worked but mine didn’t from what OP said, even though ours do practically the same thing in preventing accessories from blocking the fireball, maybe they got confused in how I wrote it.
Your implementation however has a better use if OP wants to ensure that players can’t get hurt if their accessory gets hit to ensure their hitbox isn’t increased from what they wear