I’m trying to make a physics based fire hose, works perfectly on the client and looks how it should, but whenever someone else grabs the hose it looks buggy and laggy, please see attached for the issue.
Any suggestions on how to fix it?
I’m trying to make a physics based fire hose, works perfectly on the client and looks how it should, but whenever someone else grabs the hose it looks buggy and laggy, please see attached for the issue.
Any suggestions on how to fix it?
I’d need to see your code to truly figure out what the problem is but as a guess for now it might be due to something related to network ownership.
Here’s my script below:
local ProximityPromptService = game:GetService('ProximityPromptService')
local HoseSystemFolder = game:GetService("ReplicatedStorage"):WaitForChild('HoseSystem')
ProximityPromptService.PromptTriggered:Connect(function(Prompt, Player)
if Prompt.Name == 'Grab' and Prompt.Parent.Connected.Value ~= true then
Player.Character['Right Arm'].CollisionGroup = 'Player'
Prompt.Parent.Connected.Value = true
Prompt.Parent.Connection.Value = Player
Prompt.Parent.CFrame = Player.Character['Right Arm'].CFrame
Prompt.Parent.Hold.Part1 = Player.Character['Right Arm']
Prompt.Parent.Parent.End1.Grab.Enabled = false
Prompt.Parent.Parent.End1.Roll.Enabled = false
Prompt.Parent.Parent.End2.Grab.Enabled = false
Prompt.Parent.Parent.End2.Roll.Enabled = false
HoseSystemFolder.Grab_Release:FireClient(Player, Prompt, 'Grab')
for _, part in ipairs(Prompt.Parent.Parent:GetChildren()) do
if part:IsA('BasePart') then
print('Test')
part:SetNetworkOwner(Player)
end
end
end
end)
HoseSystemFolder.Grab_Release.OnServerEvent:Connect(function(Player, Prompt, Val)
if Val == 'Release' then
Player.Character['Right Arm'].CollisionGroup = ''
Prompt.Parent.Connected.Value = false
Prompt.Parent.Connection.Value = nil
Prompt.Parent.Hold.Part1 = nil
Prompt.Parent.Parent.End1.Grab.Enabled = true
Prompt.Parent.Parent.End1.Roll.Enabled = true
Prompt.Parent.Parent.End2.Grab.Enabled = true
Prompt.Parent.Parent.End2.Roll.Enabled = true
for _, part in ipairs(Prompt.Parent.Parent:GetChildren()) do
if part:IsA('BasePart') then
print('Test')
part:SetNetworkOwner(nil)
end
end
end
end)
And could you show the client side code too?
By the way I do not recommend using ipairs, if one element in your array you’re looping through goes nil (for whatever reason) then luau stops looping through the table. So use the in operator not pairs either,
The only thing it does on the client is set the ProximityPrompt to visible (just so the person holding it sees the ProximityPrompt to be able to drop it)
Oh right, I just remembered you’re probably using a physics constraint to simulate the physics of the hose. Like a rope?
Anyways, here’s the solution probably:
You see here, on the server you’re setting the “Hold” constraint’s part1 property to the character’s right arm. So already the physics of the hose will be simulated by the server, which is already going to cause some jitter. Obviously you want the client attached to the hose to be simulating the physics of the hose to make the physics feel more responsive and smooth.
But then a few lines down, you’re doing this:
I’m assuming all these parts you’re looping through are related to the hose that you have. Now what’s wrong here? Well now you’re also simulating the physics of the hose through the client. Which in normal cases would make your hose physics feel smooth and responsive, but the problem is your previous code makes it so BOTH the server and the client are simulating the physics of the hose.
The solution to that is to simply set “Hold” Part1 property via the client. Possibly through your fireclient that you did?
Note you shouldn’t be setting this CFrame on the server either, set the CFrame through the client
Also, why exactly are you looping through each basepart and setting it’s network owner to the client? You don’t have to loop through at all. Any connected parts to your hose should be connected via weld constraints. This will create an assembly and with assemblies if you set the network ownership of any connected part to the server/client it will automatically do the same for all connected parts. So you can just set network ownership to the player for one connected part and it will set the ownership of the other connected baseparts to that player respectively.
The only thing you should really be using your remote event on the server for is to set the hose’s network owner to the client. I’m not too sure what those other values you’re setting like grab on the server actually do so I can’t really comment on that.
And please avoid using ipairs and switch to the “in” iterator not just for this but in the future, it is slower than the “in” iterator (according to benchmarks) and it will immediately stop looping through the table if it meets a nil element. (Unlikely but possible for a connected part in your hose to go nil if you have a physics based hose could get flung for whatever reason like if an exploiter flings another player their connected hose could fall in the void with them, then your code won’t work as expected).
Remember you don’t need to loop through at all so don’t even use a loop in the first place.
You can easily replicate the ipairs’ functionality with nil elements if you need to simply through checking if there’s a nil element while looping through the table and then just breaking the loop.
for _, element in mytable do
if element == nil then
break -- Stops looping through the table and breaks the loop
end
end
This code is essentially equivalent to what ipairs does, only difference is it’s faster.
Who is the network owner of the hose? You should make the network owner the client (or the player) which allows the client to do physics calculations instead of the server. I’ll link down an article about it: https://create.roblox.com/docs/physics/network-ownership
Keep in mind that if this is the solution, then hackers could manipulate the physics calculations to do some very weird stuff.
You legend, this worked. Thank you so much!!!
Yeah no problem good luck hope everything goes well.
I’m not quite sure what happened but I had it working, I changed something and then it just completely stopped working, I reverted the save to when it was working and not even that fixed it. For some reason now when I pick it up from one of the ends on the client side it shows holding the whole hose but from another client it shows holding half the hose. And then if I get the other end, it shows holding it for the client but from another client it doesn’t show holding it at all, when I let go it snaps back to where it was originally, not sure if it’s a parenting issue or something but just wanted to see if you’d have any fix for this hahaha
That might be due to a network ownership issue. Make sure all the parts in the hose are connected properly through welds or weld constraints. Maybe try setting network ownership to the assemblyrootpart if everything is connected as it should be.
They’re all connected by BallSockets and Attachments, everything worked and then all of a sudden it stopped working, I reverted the save to when I had it working and it doesn’t even work then.. I’m not quite sure what’s happened.
Yeah this is a network ownership issue probably. Could you show the code that sets network ownership?
Also, could you show how the base parts are all connected in the explorer? You said they’re connected through ball sockets and attachments?? That doesn’t connect baseparts, it wouldn’t make a true assembly.
This might be why some parts are not replicated. If this is how ur hose works then u need to set ownership individually on each part of the hose with a for loop again. But obviously with the in iterator. That way all the parts will have any physics changes replicated to all clients.
Yeah this is probably the issue. You need to set network ownership to each individual hose part. By looping through the hose model. Remember use the “in” iterator.
You see, this isn’t an assembly. They aren’t truly connected base parts. Ball socket constraints just forces the attachments to occupy a position. Not a true connection.
Roblox considers a group of base parts an “assembly” when they’re connected via welds, weld constraints, or motor6ds. Since they create true connections.
This is why for player characters you can set network ownership to only one character basepart and it will set that same ownership to all the character’s baseparts. Because a player character is considered an assembly due to being connected via welds and motor6ds.
Whereas, for you. Roblox rightfully doesn’t consider your hose as an assembly. Since they aren’t truly all joined together.
If the issue persists, turn on network owners visible settings in studio. To help debug the problem.
I think I know what the issue might be then, it’s still due to network ownership. But not due to incorrect setting of ownership.
You had an object named “Hold” which I assumed was a weld or weld constraint? I told you to set hold’s part0 and part1 property on the client. However this is a mistake.
For security reasons, setting those properties of hold “Part0/Part1” on the client will not replicate to the server and then all connected clients. This is probably the issue. But you also don’t wanna go back to setting hold’s part1 on the server because then you’ll get the old problem. So what’s the real solution?
Simple fix would be to just use fireallclients, you set hold’s part1 property in the onclientevent and it’ll replicate to the other clients. The server won’t see anything though obviously. You can do this if you can’t be bothered with the idea below.
The long-term solution would be to not replicate at all. This is a more complex route but this will actually benefit performance since the server will have to do less replication it can focus on other priority tasks leading to potentially more client fps and lower ping. also benefits gameplay since even with network ownership there will be less smooth/responsive physics for clients that aren’t attached to the hose due to how Roblox replication works (which is kind of alright I guess due to how Roblox latency works). and there are no security vulnerabilities.
You’ll need a client sided proximity prompt event, when it’s fired u get the player that triggered it. Then u set hold’s part1 property.
You will still need to use the server-side proximity prompt event to handle calculations. Like that connected Boolean you had? Only you know about the ins and outs of your game best so I can’t really help you there but you’d be fine I’d say
Yeah this should work now, this won’t be seen on the server though. Only on other clients’ devices. You need to test on two clients’ screens. From the video you showed me you only checked on the server and not other clients.