Im trying to use GetPartsInPart() to make a hitbox. This hitbox can be moved within a short time before it is destroyed and because of that im using a while hitbox.Parent do loop to get new parts in that part if it changes the position.
The problem is that the server “sees” that part in an static position instead of updating it. But if i try the same code on the client then it works perfectly fine, it prints the position as it should be.
Code:
local HitboxCFrame = Player.Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-4)
local HitboxSize = Vector3.new(5,5,6)
local HitboxName = "NormalPunchHitbox"
local HitboxShape = Enum.PartType.Block
local HitboxLifetime = .3
local HitboxParent = Player.Character
local HitboxWelded = true
local WeldPart0 = Player.Character.HumanoidRootPart
local newHitbox = Instance.new("Part")
newHitbox.CFrame = HitboxCFrame
newHitbox.Size = HitboxSize
newHitbox.Name = HitboxName
newHitbox.Shape = HitboxShape
newHitbox.CanCollide = false
newHitbox.Anchored = true
newHitbox.Massless = true
newHitbox.Transparency = 0.5
newHitbox.CastShadow = false
newHitbox.Parent = HitboxParent
if HitboxWelded then
local HitboxWeld = Instance.new("WeldConstraint")
HitboxWeld.Parent = newHitbox
HitboxWeld.Part0 = WeldPart0
HitboxWeld.Part1 = newHitbox
newHitbox.Anchored = false
end
game.Debris:AddItem(newHitbox, HitboxLifetime)
while newHitbox.Parent do
print(newHitbox.Position)
task.wait()
end
Here is how it prints the position of the part on the client (how it should be):
Here is how it prints the position of the part on the server:
Note that on the server the position only changes when the loop starts and only when it ends instead of updating in every iteration.
Anything that is being done by the client, such as updating the position through a local/client script or interacting with the use of the studio’s tools, is only visible from the client side. In this case, probably the reason why the output from the client and the server is different is because on the client side, you are directly interacting with the object, such as using the studio’s tools or the client’s script.
Well, really, I don’t understand the main issue here as to what you are doing; I am just basing this on observing the script that was provided.
Hello, thank you for your answer.
Im not trying to do that, im trying to figure out why the getPartsInPart() searchs for parts “in an old part position”, here is a better look at the issue:
the part you see in the video is the one wich i look for parts inside of it on a loop but when i spam it then it stays like the first time i call the function.
Here is that piece of code:
function HandleHitboxDetectionWithGetParts(Hitbox, Filter, onDetection)
local EnemiesHitted = {}
while Hitbox.Parent do
local PartsInsideHitbox = workspace:GetPartsInPart(Hitbox, Filter, onDetection)
for _,Part in PartsInsideHitbox do
local PotentialEnemyCharacter = Part:FindFirstAncestorWhichIsA("Model")
if PotentialEnemyCharacter and not EnemiesHitted[PotentialEnemyCharacter] then
if PotentialEnemyCharacter:FindFirstChildOfClass("Humanoid") then
print(PotentialEnemyCharacter)
EnemiesHitted[PotentialEnemyCharacter] = true
onDetection(PotentialEnemyCharacter)
end
end
end
task.wait()
end
Hitbox = nil
end
That could be because the part’s position is only being updated by the client, which is the weld from the first code that you provided:
My guess is that this is on a client script. If that weren’t the case, then you could double check it while running the game. While doing the action/attack, try to switch to the server’s perspective and go near the character to see if the hitbox is there or following the player.
im not doing any weld on the client, the first code i provided was to test that print functionality. Weld and part is created by the server. Anyways i should change the topic because i think i explained and approached it wrong
The problem was in the WeldConstraint that made the player’s and hitbox CFrame not replicate to server (even if i create the part and weld on the server), i’ll make a post about it.