Need a little assistance with a script!

Yeah so that works, the thing that bothers me is that my controlls dont work and i have not a single idea of why, here is the controll script:

local Ball = game.Workspace:WaitForChild("Ball")
local Char = Ball.Parent
local uis = game:GetService("UserInputService")





uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if not gameProcessedEvent then
		local currentVelocity = Ball.Velocity
		local speed = 20

		if input.KeyCode == Enum.KeyCode.A then
			Ball.Velocity = Vector3.new(-speed, currentVelocity.Y, currentVelocity.Z)
		elseif input.KeyCode == Enum.KeyCode.D then
			Ball.Velocity = Vector3.new(speed, currentVelocity.Y, currentVelocity.Z)
		end
	end
end)

but the egg shaped ball is gone. Thank you very much.

I think you are looking in the wrong placeā€¦
Get the player character.
Then when the user presses the key, look for the ball in the character. (It might not be there when the script first runs).

i made it script.Parent but its still not rolling, this is so frustrating

Does really no one have a fix? I just need the controlls and the ball being a ball and not a egg what actually works.

Try this code:

local Players = game:GetService('Players')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local UserInputService = game:GetService('UserInputService')

local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Ball = Character:WaitForChild('Ball')

local BV = Instance.new('BodyVelocity')
local Speed = 20

BV.MaxForce = Vector3.new(math.huge, 0, math.huge)
BV.Velocity = Vector3.new(Speed, 0, 0)
BV.Name = 'BALL_Velocity'
BV.Parent = Ball

UserInputService.InputBegan:Connect(function(InputObject, GPE)
	if not GPE then
		local KeyCode = InputObject.KeyCode

		if KeyCode == Enum.KeyCode.A then
			BV.Velocity += Vector3.new(0, 0, Speed)
		elseif KeyCode == Enum.KeyCode.D then
			BV.Velocity += Vector3.new(0, 0, -Speed)
		end
	end
end)

UserInputService.InputEnded:Connect(function(InputObject, GPE)
	if not GPE then
		local KeyCode = InputObject.KeyCode

		if KeyCode == Enum.KeyCode.A or KeyCode == Enum.KeyCode.D then
			BV.Velocity = Vector3.new(Speed, 0, 0)
		end
	end
end)

Sorry i was afk, but ur code doesnt work either

Thats actually rlly weird i just tried adding a ball to my character and i got the same thing,
image

image

i changed the dimensions of the ball to be equal and it stoped stretching

yeah so, the size and everything works but the controlls suddenly stopped working

Thats weird, is ther elike any errors or anything

Also if ur contgrols were wrking before u tried the other code and allat maybe revert back to a working version and set size to a cube again and see ift hat works

When I do that, then it just wonā€™t work, its when the ball Is a egg, the controls work and if the ball is not a egg the controls wonā€™t work

Thats rlly weird actually, Ur sure the ball ur trying to move in the localscript is the ball from ur character?

itā€™s a server sided script parented in server script service, the reason for that is that when it was a local script, the ball only moved on the client and the whole games mechanic just wouldnā€™t work, so thatā€™s why I made it a server sided script but yes Iā€™m sure that the ball Iā€™m tryna move is in the character

userinputservice and stuff doesnt work from the server script, so maybe set the network ownership of the ball to the player (by parenting the ball to the character) and make the server script local again

Making it local breaks the game as i said, but i can maybe do it using remote events, thanks

Yeah that will work, but you should be able to change the parts velocity if the character which is moving it has network ownership

Nah im giving up, i cant do it, nothing work im getting more frustrated im closing this

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