I want to have a ball move when I hit W... I succesfully put in place the movement and I have the BodyVelocity in the script. I set the MaxForce and Velocity all to zero so when I'm not hitting w the ball will roll will gravity. The UserInputService is working but I get the error message "X cannot be assigned to"... thats it, it doesn't say what the coordinate x cannot be assigned to... Eventually I will have a system in place so the ball slows down with gravity instead of stopping immidiatly but here is what I have now. This is all in a local script.
local UIs = game:GetService('UserInputService') local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local Key = 'W' UIs.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] then script.Parent.BodyVelocity.Velocity.X = 50 script.Parent.BodyVelocity.MaxForce.X = 100 end end)
You cannot set individual components of Vector3
values. Here's how you fix that:
local UIs = game:GetService('UserInputService') local plr = game.Players.LocalPlayer local Char = plr.Character or plr.CharacterAdded:Wait() local Key = 'W' UIs.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end local KeyPressed = Input.KeyCode if KeyPressed == Enum.KeyCode[Key] then script.Parent.BodyVelocity.Velocity = Vector3.new(50,script.Parent.BodyVelocity.Velocity.Y,script.Parent.BodyVelocity.Velocity.Z) script.Parent.BodyVelocity.MaxForce = Vector3.new(100,script.Parent.BodyVelocity.MaxForce.Y,script.Parent.BodyVelocity.MaxForce.Z) end end)