Hello Developers, I require your help! I always try to use UIS but it never works when I try to use it. Today, I was bored and decided to experiment with it - but it did not work. I decided to make a basic shift to sprint script, which does not work… At all. I have included a code block below, this is the code I have tried. I tried looking at the DevWiki API reference- still did not work.
Please let me know if you can help.
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)
--//
local UserInputService = game:GetService("UserInputService")
--//
UserInputService.InputBegan:Connect(function(Input)
if Input == Enum.KeyCode.LeftShift then
hum.WalkSpeed = 26
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input == Enum.KeyCode.LeftShift then
hum.WalkSpeed = 16
end
end)
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)
--//
local UserInputService = game:GetService("UserInputService")
--//
UserInputService.InputBegan:Connect(function(Input)
if Input.Keycode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = 26
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = 16
end
end)
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)
--//
local UserInputService = game:GetService("UserInputService")
--//
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = 26
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = 16
end
end)
This still does not work? I added prints into my script too…
Video to show;
The script which I used;
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(char)
--//
local UserInputService = game:GetService("UserInputService")
--//
UserInputService.InputBegan:Connect(function(Input)
print("input detected")
if Input.KeyCode == Enum.KeyCode.LeftShift then
print("keycode was lefshift")
hum.WalkSpeed = 26
end
end)
UserInputService.InputEnded:Connect(function(Input)
print("input detected")
if Input.KeyCode == Enum.KeyCode.LeftShift then
print("keycode was lefshift")
hum.WalkSpeed = 16
end
end)
Oh, make sure your code is a LocalScript.
Since LocalScripts are client sided you need to create RemoteEvents to send information to server, so basically when you detect the input, fire the RemoteEvent and receive the information then set the speed in the server.
No, that’s what you’d think. Character movement (and 99% sure physics in general in roblox, but don’t quote me on that) are automatically replicated across the server
Ah my bad, It does replicate the movements but I don’t think I suggest using this because changing the properties from the client doesn’t replicate in server properties. Which is a bad practice.
Thanks a ton! This cleared up ALOT for me! Here is the script I used:
StarterCharacterScript;
local char = script.Parent
local player = game.Players:GetPlayerFromCharacter(char)
--//
local UserInputService = game:GetService("UserInputService")
local ReplicateStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicateStorage:WaitForChild("RemoteEvent")
--//
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
RemoteEvent:FireServer("ShiftToSprint",{26})
end
end)
UserInputService.InputEnded:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
RemoteEvent:FireServer("ShiftToSprint",{16})
end
end)
Then the script which handles RemoteEvent in ServerScriptService;
local repstore = game:GetService("ReplicatedStorage")
local remote = repstore:WaitForChild("RemoteEvent")
remote.OnServerEvent:Connect(function(Player, Type, InfTable)
if Type == "ShiftToSprint" then
local Speed = tonumber(InfTable[1])
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.WalkSpeed = Speed
end
end)
You need to put keycode I think, and it needs to be a local script inside of StarterGui, or PlayerScripts.
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.LeftShift then
hum.WalkSpeed = 26
end
end)