I am making a movement a script for the game I a working on. I want to make the sprinting work on a server script. How would I be able to do that?
You first need to make a fire event in the client with “ContextActionService”, after that make a “RemoteEvent” that fires a script in the “Server” with a function that add more “WalkSpeed” and a cool “Animation” to the “Character”. That’s the fastes way, there are multiple ways to do this, good luck!
Here more information about it:
https://developer.roblox.com/en-us/api-reference/class/ContextActionService
3 Likes
local script
local UIS = game:GetService("UserInputService")
local event = game.ReplicatedStorage.SprintEvent
UIS.InputBegan:Connect(function(i,gpe)
if not gpe then event:FireServer(i.KeyCode,true) end
end)
UIS.InputEnded:Connect(function(i,gpe)
if not gpe then event:FireServer(i.KeyCode,false) end
end)
serverscript
local event = game.ReplicatedStorage.SprintEvent
event.OnServerEvent:Connect(function(plr,key,status)
if key and key == Enum.KeyCode.LeftShift then
plr.Character:WaitForChild("Humanoid").WalkSpeed = status and 24 or 16
end
end)
Tested and works 100%
1 Like