Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

AssemblyLinearVelocity not working on players. Any explanations ?

Asked by 1 year ago

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 ?

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

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 RemoteEvents 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.

0
Hello! I would like to say that you answeri right, but i have tried everything to make it but it works but it won't. I don't know why it was working with a raycast i made earlier without having to use the SetNetworkOwnership but now it seems that the SetNetworkOwnership doesn't make any changes but i am actually sure it should do something. Thanks for the answer very well detailled. Fouxelefr 7 — 1y
0
Yessss just found the answer! II serached up for SetNetworkOwnership() and found SetNetworkOwnerAuto() which reset the SetNetworkOwnership on the devhub and it works perfectly! thanks you for giving me a clue to help me ! Fouxelefr 7 — 1y
0
There are 2 choices: Using a RemoteEvent, or using :SetNetworkOwnership(). If one of the choices doesn't work, just do the other choice. T3_MasterGamer 2189 — 1y
0
But still, you're welcome! T3_MasterGamer 2189 — 1y
View all comments (3 more)
0
Please upvote my answer! So that I get more reputation :D (dw i upvoted your question too) T3_MasterGamer 2189 — 1y
0
i can't because i am actually new to this site I will when i will have more than 25 reputation! Fouxelefr 7 — 1y
0
okay! T3_MasterGamer 2189 — 1y
Ad

Answer this question