My script is not working, and it doesn’t give any errors, and whenever I’m cloning hitbox, it doesn’t get welded. Thank you for reading!
game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player)
local clone = game.ReplicatedStorage.HitBox:Clone()
clone.Parent = game.Workspace
local char = player.Character or player.CharacterAdded:Wait()
clone.WeldConstraint.Part1 = char:FindFirstChild("Torso")
clone.WeldConstraint.Part0 = clone
clone.Touched:Connect(function(Hit)
local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
if plr and plr.Name ~= player.Name then
local dir = (Vector3.new(-7.5, 3, 14.95) - Vector3.new(-7.5, 3, 10.9)).Magnitude
plr:MoveTo(plr:FindFirstChild("HumanoidRootPart").Position + Vector3.new(dir,0,0))
local plrchar = plr.Character or plr.CharacterAdded:Wait()
local anim = plrchar:FindFirstChild("Humanoid"):LoadAnimation(script.Punch2)
local anim2 = char:FindFirstChild("Humanoid"):LoadAnimation(script.Punch)
anim:Play()
anim2:Play()
end
end)
end)
Its because sometimes player’s character is R15 and R15 doesn’t have Torso. You can weld to HumanoidRootPart if you want. You can make this:
clone.WeldConstraint.Part1 = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart")
And, if you want to hitbox move with player, then you need to set Part0 to Torso or HumanoidRootPart. Part1 to hitbox. Here is updated code:
game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player)
local clone = game.ReplicatedStorage.HitBox:Clone()
clone.Parent = game.Workspace
local char = player.Character or player.CharacterAdded:Wait()
clone.WeldConstraint.Part1 = clone
clone.WeldConstraint.Part0 = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart")
clone.Touched:Connect(function(Hit)
local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
if plr and plr.Name ~= player.Name then
local dir = (Vector3.new(-7.5, 3, 14.95) - Vector3.new(-7.5, 3, 10.9)).Magnitude
plr:MoveTo(plr:FindFirstChild("HumanoidRootPart").Position + Vector3.new(dir,0,0))
local plrchar = plr.Character or plr.CharacterAdded:Wait()
local anim = plrchar:FindFirstChild("Humanoid"):LoadAnimation(script.Punch2)
local anim2 = char:FindFirstChild("Humanoid"):LoadAnimation(script.Punch)
anim:Play()
anim2:Play()
end
end)
end)
I see why it wasn’t moving along with the player, I had to put the clone’s position to the humanoidrootpart’s position. It’s moving along now. But I can’t move. And also my position is changing according to the magnitude, although in the script it says plr.Name ~= player.Name.
You can’t use :MoveTo() function with player you need to change it to humanoid. The only move function you can use with player variable is :Move() function. And also you need to unanchor the hitbox to be able to move. And close cancollide
I dont know what you’re mentioning over here. But might be a problem. If this script works then no problem:
game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player)
local clone = game.ReplicatedStorage.HitBox:Clone()
clone.Parent = game.Workspace
local char = player.Character or player.CharacterAdded:Wait()
clone.WeldConstraint.Part1 = clone
clone.WeldConstraint.Part0 = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart")
clone.Touched:Connect(function(Hit)
local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if plr and plr.Name ~= player.Name and Humanoid ~= nil then
local dir = (Vector3.new(-7.5, 3, 14.95) - Vector3.new(-7.5, 3, 10.9)).Magnitude
Humanoid:MoveTo(plr:FindFirstChild("HumanoidRootPart").Position + Vector3.new(dir,0,0))
local plrchar = plr.Character or plr.CharacterAdded:Wait()
local anim = Humanoid:LoadAnimation(script.Punch2)
local anim2 = Humanoid:LoadAnimation(script.Punch)
anim:Play()
anim2:Play()
end
end)
end)
This works fine, but now there are just 2 problems, what I meant with “And also my position is changing according to the magnitude” was that whenever the hitbox is touched I don’t want the player’s position to change, I want everyone else’s position change. and also the animations aren’t working.
I don’t know, what you’re talking about but if you want all the players position change then if someone touched to the hitbox get all players with game.Players:GetPlayers() and get their character. Then change their positions. I need to know what you’re doing or i can’t help you. And you said animations are’nt working try this:
game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player)
local clone = game.ReplicatedStorage.HitBox:Clone()
clone.Parent = game.Workspace
local char = player.Character or player.CharacterAdded:Wait()
clone.WeldConstraint.Part1 = clone
clone.WeldConstraint.Part0 = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart")
clone.Touched:Connect(function(Hit)
local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if plr and plr.Name ~= player.Name and Humanoid ~= nil and Humanoid.Parent ~= player.Name then
local dir = (Vector3.new(-7.5, 3, 14.95) - Vector3.new(-7.5, 3, 10.9)).Magnitude
Humanoid:MoveTo(plr:FindFirstChild("HumanoidRootPart").Position + Vector3.new(dir,0,0))
local plrchar = plr.Character or plr.CharacterAdded:Wait()
local anim = plrchar:FindFirstChild("Humanoid"):LoadAnimation(script.Punch2)
local anim2 = char:FindFirstChild("Humanoid"):LoadAnimation(script.Punch)
anim:Play()
anim2:Play()
end
end)
end)
What I’m trying to do is, whenever another player touches the hitbox, he will move infront of him. but what’s happening now is, the player with the hitbox is also moving.
game.ReplicatedStorage.Punch.OnServerEvent:Connect(function(player)
local clone = game.ReplicatedStorage.HitBox:Clone()
clone.Parent = game.Workspace
local char = player.Character or player.CharacterAdded:Wait()
clone.WeldConstraint.Part1 = clone
clone.WeldConstraint.Part0 = char:FindFirstChild("Torso") or char:FindFirstChild("HumanoidRootPart")
clone.Touched:Connect(function(Hit)
local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if plr.Name == player.Name and Humanoid.Parent.Name == player.Name then return end
if plr and Humanoid ~= nil then
local dir = (Vector3.new(-7.5, 3, 14.95) - Vector3.new(-7.5, 3, 10.9)).Magnitude
Humanoid:MoveTo(plr:FindFirstChild("HumanoidRootPart").Position + Vector3.new(dir,0,0))
local plrchar = plr.Character or plr.CharacterAdded:Wait()
local anim = plrchar:FindFirstChild("Humanoid"):LoadAnimation(script.Punch2)
local anim2 = char:FindFirstChild("Humanoid"):LoadAnimation(script.Punch)
anim:Play()
anim2:Play()
end
end)
end)