I want to create a custom movement system where the player controls a velocity based ball. Most tutorials I have seen just change the character, keeping the old movement. When trying to make it completely custom I did not know how best to communicate between the client and the server, for stuff like when the player is holding a button, and the orientation of the camera. I am trying to make a physics based arena game where players collide, so I think I need most movement to be on the server. Overall I am pretty overwhelmed and confused and any help would be appreciated.
It sounds like you need help with design, here what you need to get started:
-
LocalScript - in StarterCharacterScripts
Only write things in this script that happen on the client side, like camera movement and user input. Use a RemoteEvent to send messages to the server when the user input happens. -
RemoteEvent - in ReplicatedStorage, to communicate from client to server
You can use remote events to send info to the server about what the player is doing. -
Script - in ServerScriptService, to listen for when the Remote Event happens
This will control whatever happens in the game world, based on your user input.
If you’re overwhelmed, try to simplify what you’re trying to make. A lot of the time, there is no need to reinvent the wheel… Roblox provides a lot of simplified objects that you can use rather than making something custom.
Thank you! One of the main things I was worrying about was overusing remoteevents, and if firing one every frame is normal or should be avoided. I stumbled upon this code:
local Player = game:GetService('Players').LocalPlayer; local InputService = game:GetService('UserInputService'); local Camera = workspace.CurrentCamera; local Settings = { Speed = 30, JumpPower = 60, Size = Vector3.new(5, 5, 5) }
local Character = Player.Character or Player.CharacterAdded:Wait();
local Humanoid = Character:WaitForChild('Humanoid');
local RayParams = RaycastParams.new();
local Ball = Character:WaitForChild('Ball');
local Connection;
Camera.CameraSubject = Ball
RayParams.FilterType = Enum.RaycastFilterType.Exclude;
RayParams.FilterDescendantsInstances = {Character};
for _, v in next, Player.Character:GetChildren() do if v:IsA('BasePart') and v ~= Ball then v.Massless = true; v.CanCollide = false; end end
Humanoid.Died:Connect(function() Connection:Disconnect() end);
Connection = game:GetService('RunService').RenderStepped:Connect(function(delta)
Humanoid.PlatformStand = true;
Ball.CanCollide = true;
if InputService:IsKeyDown('W') then
Ball.RotVelocity -= Camera.CFrame.RightVector * delta * Settings.Speed
end
if InputService:IsKeyDown('A') then
Ball.RotVelocity -= Camera.CFrame.LookVector * delta * Settings.Speed
end
if InputService:IsKeyDown('S') then
Ball.RotVelocity += Camera.CFrame.RightVector * delta * Settings.Speed
end
if InputService:IsKeyDown('D') then
Ball.RotVelocity += Camera.CFrame.LookVector * delta * Settings.Speed
end
end)
InputService.JumpRequest:Connect(function() if workspace:Raycast(Ball.Position, Vector3.new(0, -((Ball.Size.Y / 2) + 0.3), 0), RayParams) then Ball.Velocity = Ball.Velocity + Vector3.new(0, Settings.JumpPower, 0) end end)
This is a local script, but it also seems to affect the server. Is there any explanation for this, becuase I thought usually local scripts do not change things on the server.
You should not have to fire an event every frame, you could instead fire events when there is a change. Keep in mind that events occurring on the server generally propagate to also happen on all clients.
I wrote a post that might help you set up a controller script -
Cross-platform controls - Easy method - Resources / Community Resources - Developer Forum | Roblox
If you are trying to make the player walk forward in direction of the camera, would there be any way other than firing an event when the player moves the camera?
Camera happens on the client side so you won’t need to use events.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.