Script wont work when it works in command line

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? AssemblyLinearVelocity working

  2. What is the issue? When i type in the script game.Workspace:FindFirstChild(“Maratyla10”): FindFirstChild(“HumanoidRootPart”).AssemblyLinearVelocity = Vector3.new(0, 100, 0) it doesnt work, but when i do it with command line it does work

  3. What solutions have you tried so far? Changing the findfirstchild to torso (did the same result)

please help

1 Like

four letters, one word, one syllable

what?

1 Like

The character probably didn’t load in yet. Try this in a LocalScript:

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local hrp = character:WaitForChild("HumanoidRootPart")
hrp.AssemblyLinearVelocity = Vector3.new(0, 100, 0)
3 Likes

wait you should do it in localscript?

It doesn’t really matter, I chose a LocalScript because it was less code to write here and it would basically have the same effect (clients have network ownership of their characters so effects replicate, but the server would not receive the updated value).

Note to use a server script you would need to change the code.

I solved it by myself.

  1. Create any part
  2. Create the “PadEvent” remote event in replicatedstorage
  3. Add script to part
  4. Add local script to replicatedFirst
    Script: game.Players.PlayerAdded:Connect(function(player)
    script.Parent.Touched:Connect(function(hit)
    game.ReplicatedStorage.PadEvent:FireClient(player, hit)
    end)
    end)
    Local script: game.ReplicatedStorage:WaitForChild(“PadEvent”).OnClientEvent:Connect(function(hit)
    print(“Working”)
    hit.AssemblyLinearVelocity = Vector3.new(0, 100, 0)
    end)

That system is very inefficient, creates memory leaks, and comes with the issue where one player stepping on it sends all players flying. You can just use one script in the part:

local players = game:GetService("Players")

local part = script.Parent

local function onTouch(hit: BasePart): nil
    local player = players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local rootPart = hit.Parent:FindFirstChild("HumanoidRootPart", false)
        rootPart.AssemblyLinearVelocity = Vector3.new(0, 100, 0)
    end
end

part.Touched:Connect(onTouch)
1 Like

It shouldn’t make all players jump, but it uses unnecessary memory, creates memory leaks, and it binds the event multiple times. I think the easiest thing is to create a script in the part and set the run context to client and just use the Touched event

The script would make all players jump because it creates a new connection for the .Touched event each time a player joins and essentially fires the event to all players in the game. Changing the RunContext to client on their script would have no effect because each client would fling each other locally and end up in the same result. Removing the PlayerAdded event just causes other client’s characters to be flung locally.

I was confused but I understand how it makes all players jump, but I was talking about creating a new script. Regardless of that, the AssemblyLinearVelocity should be added on to instead of being set to a constant.

it pushes me like, i ate too much and it fails to push me

this script worked just like i needed! I just set runcontext to client! thanks

1 Like

another solution is creating a part, anchoring it, and set part’s assemblylinearvelocity to 0, (anyvalue), 0, it doesnt even require scripting!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.