So i have been trying to make something like when the player is touched by an object, the client sided script send a remote to the server sided script to make the other player flies. It works for dummies but when i am testing with a player, it doesn't works anymore.
Here is a part of my server sided script:
hithrp.AssemblyLinearVelocity = Vector3.new(100,60,0) -- works for dummies but not for players
What should i do ?
It's because of Network Ownership. All limbs of the dummies/NPCs are owned by the server, while the limbs of the players are owned by the players themselves. Because of that, you need to use AssemblyLinearVelocity
in the Client-side.
You can use RemoteEvent
s to communicate with the client, or temporarily set the NetworkOwnership
to the server.
• Using a RemoteEvent
-- Server (Normal Script in Workspace or ServerScriptService) -- local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage.RemoteEvent -- imagine that there's a remote event named "RemoteEvent" in ReplicatedStorage -- lines of code later... local player = Players:GetPlayerFromCharacter(hithrp.Parent) if player then -- if it's a real player RemoteEvent:FireClient(player) -- you have to define the "RemoteEvent" variable and the "player" variable yourself so this will work end -- the rest of the code -- Client (Local Script in StarterPlayerScripts) -- local Players = game:GetService("Players") local Player = Players.LocalPlayer local ReplicatedStorage = game:GetService("ReplicatedStorage") local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") -- imagine that there's a remote event named "RemoteEvent" in ReplicatedStorage RemoteEvent.OnClientEvent:Connect(function() local character = player.Character or player.CharacterAdded:Wait() local hrp = character:WaitForChild("HumanoidRootPart") hrp.AssemblyLinearVelocity = Vector3.new(100, 60, 0) end)
• Setting NetworkOwnership
to Server temporarily
-- Server (Normal Script in Workspace or ServerScriptService) -- local Players = game:GetService("Players") -- lines of code later... local player = Players:GetPlayerFromCharacter(hithrp.Parent) if player then -- if it's a real player hithrp:SetNetworkOwnership(nil) -- sets NetworkOwnership to server hithrp.AssemblyLinearVelocity = Vector3.new(100,60,0) task.wait(2) hithrp:SetNetworkOwnership(player) -- sets NetworkOwnership back to original owner (aka the client or the player themself) end -- the rest of the code
ALSO DO NOT COPY AND PASTE THIS ANSWER DIRECTLY TO YOUR CODE BECAUSE IT WON'T WORK. THIS JUST SHOWS OF WHAT YOU WILL DO AND EDIT IN YOUR CODE TO MAKE IT WORK.