Hi everyone. Hopefully this is a simple one and I’m missing some fundamental fact. I’m sending a remote from the server to the client to Reduce gravity and then shoot the a specific player or players up in the air.
The script works perfectly if there is a single player on the server. As soon as there is more than one player on the server it fails. No errors. Just does nothing. I put a print statement in the client side and it definitely runs the Remote but nothing happens.
The client script is short and sweet and is sitting under StarterPlayerScripts:
ClientGravityLaunch.OnClientEvent:Connect(function(gravityNum)
local character = player.Character or player.CharacterAdded:Wait()
local HumanRoot = character:WaitForChild("HumanoidRootPart")
workspace.Gravity = gravityNum
HumanRoot:ApplyImpulse(Vector3.new(0,250,0))
end)
ClientGravityNormal.OnClientEvent:Connect(function()
workspace.Gravity = 196.2
end)
The server script runs through a table of players and sends the Remote to a specific player or players
Edit: My bad, I skimmed your post and have just noticed you’re running this on the client - somehow managed to be confidently incorrect!
Anyway:
Are you able to show the script that sends the event? And also, do you have any output information for whether the information is received by the client(s)?
I note you said there’s a print statement, but do you know if it reached the HumanRoot:ApplyImpulse(Vector3.new(0, 250, 0)) line?
Original, incorrect comment:
There is one thing you may have over looked, that being NetworkOwnership - you can read more about that here.
The Instance<BasePart>::ApplyImpulse() method documentation, found here, notes that:
If the part is owned by the server, this function must be called on a server Script. If the part is owned by a client, this function can be called on a LocalScript or server Script.
The issue is that the server doesn’t have network ownership of the HumanoidRootPart so it’s unable to apply an impulse to that object.
You would have to either:
Claim ownership of the HumanoidRootPart on the server before applying the impulse, e.g.HumanRoot:SetNetworkOwner(nil)
This is a bit of a tricky one since the client can reclaim ownership through its Humanoid instance
and; if it didn’t, you would have to ensure you gave the network ownership back to the client
Modify your current logic such that:
Allow the client to perform the impulse but validate it on the server before enacting it, e.g.
The client would send a request to ClientGravityLaunch to request an impulse
The server validates that input and then sends an event to the client to confirm / reject the request
The client can then call the ::ApplyImpulse() on itself
Also, I should note: unsure if you intended to do this but by setting the Gravity property of workspace on the server you are replicating that change to all clients on the server, not just that particular client. You would need to do that on the client if you wanted to modify the workspace gravity for only that client.
Thanks for the reply
The above first script is already on the client side. That’s why I have the gravity modifier in there.
It actually works fine until there is more than one player on the server.
Yeah I’d noticed, sorry about that - I had edited my post above but must have been a bit too slow for you before you’d started your reply!
I had added this bit, but also another question also:
“It actually works fine until there is more than one player on the server.”
Does this mean you’re no longer receiving the event once more than one player joins; or that you aren’t seeing the same effect despite receiving the event i.e. you can still see output information that shows both players are getting the event?
Yeah its really weird. The print statement in the client fires and prints the gravityNum on both clients.
Ill run it again with a print before and after the impulse and see how far it gets.
All i’m doing on the server is creating a table of players to receive the impulse and then looping through each player and firing the client. I’m going to throw a wait after each client fire. Can’t see it making a difference but ya never know. Ill test and be back…
lol, dude. After some testing I figured it out.
The other test player was to fat to launch!
I had no idea that the dimensions of Body Size in an R15 Character played a role in their weight in a game. As soon as I made the character skinny, up he went.
I couldn’t stop laughing…
So now I have to figure out how to get the players character Body Size so I can calculate how much Impulse to apply. Cause I need all players to fly up roughly the same height. I’m sure there will be something in the forum for that, unless anyone knows off the top of their head now…
Yep, all sorted. AssemblyMass did the trick.
this is for anyone else come across the same issue. Get the Mass first and use it in your Impulse calculation. I didn’t bother with gravity calc for mine but I imagine that would play a role in it to. Anyway this works for me perfectly
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
-- Get total Mass of player for Impulse
if char then
mass = 0
for i,v in pairs(char:GetDescendants()) do
if(v:IsA("BasePart")) then
mass += v.AssemblyMass
end
end
end
ClientGravityLaunch.OnClientEvent:Connect(function(gravityNum)
local character = player.Character or player.CharacterAdded:Wait()
local HumanRoot = character:WaitForChild("HumanoidRootPart")
workspace.Gravity = gravityNum
HumanRoot:ApplyImpulse(Vector3.new(0,mass * 1.5 ,0))
end)