#chat i dont code offten so im not the best at diagnosing whats wrong but whatd i do wrong???
123 messages · Page 1 of 1 (latest)
UserInputService.InputBegan:Connect(sprint)
but u would use
Enum
if Enum.UserInputType == Shift then
alright thanks bro
Enum.KeyCode.LeftShift i think
ohh
and u should do
if input.KeyCode == Enum.KeyCode.LeftShift then
...
end
i have the script in starter player is that alright? or would that mess soemthign up
yes, it needs to be a localscript and having it in starterplayerscripts is good, so only run when the player is loaded
don't create the function inside the UIS event, instead put it outside before the event and call it using the UIS event
** You are now Level 7! **
Userinputservice
how
like this ? ```lua
local Shift = Enum.KeyCode.LeftShift
local UserInputService = game:GetService("UserInputService")
local player = script.Parent
if Enum.KeyCode == Shift then
player.Parent.CharacterWalkSpeed = (16)
end
@dull notch
wait I'll remake your code
alright
local shift = Enum.KeyCode.LeftShift
local UserInputService = game:GetService("UserInputService"(
local player = script.Parent
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local function sprint()
humanoid.WalkSpeed = 30
end
UserInputService.InputBegan:Connect(function(input, isProcessed)
if input.KeyCode == shift then
sprint()
end
end)
UserInputService.InputEnded:Connect(function(input, isProcessed)
if input.KeyCode == shift then
humanoid.WalkSpeed = 16
end
end)
damn that js made it so much more complicated than id think 😭
alright im gunna try to use your code and work it into what i made i dont like blatenly copieying
no it will not work
so ill let yk when it works
for multiple reasons
whyM
- there is a flipped bracket, 2 the parent of the script is not the player object but rather PlayerScripts
the local script is on StarterPlayerScripts
local shift = Enum.KeyCode.LeftShift
local UserInputService = game:GetService("UserInputService")
local player = script.Parent
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local function sprint()
humanoid.WalkSpeed = 30
end
UserInputService.InputBegan:Connect(function(input, isProcessed)
if input.KeyCode == shift then
sprint()
end
end)
UserInputService.InputEnded:Connect(function(input, isProcessed)
if input.KeyCode == shift then
humanoid.WalkSpeed = 16
end
end)
@pliant fossil
also im 99% sure this breaks when you respawn
wait
icy
sup bro
just replace the player path to game.Players.LocalPlayer
local Shift = Enum.KeyCode.LeftShift
local UserInputService = game:GetService("UserInputService")
local player = script.Parent
local function sprint(InputType) if Enum.InputType == Shift then
player.Parent.locaCharacterWalkSpeed = (16)
end
end
UserInputService.InputBegan:Connect(sprint)``` so this is my script can you js say whats wrongwith it
player.Parent.locaCharacterWalkSpeed isnt a real thing
try this again
local shift = Enum.KeyCode.LeftShift
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local function sprint()
humanoid.WalkSpeed = 30
end
UserInputService.InputBegan:Connect(function(input, isProcessed)
if input.KeyCode == shift then
sprint()
end
end)
UserInputService.InputEnded:Connect(function(input, isProcessed)
if input.KeyCode == shift then
humanoid.WalkSpeed = 16
end
end)
you need to change humanoid.WalkSpeed instead
@pliant fossil
again, it breaks when you respawn
Ok so:
when you first set Character to be player.character it points to the model in workspace,
when you respawn, that object is destroyed, and Character points to nill now
yeah so it needs to remake and put in StarterCharacterScripts
but I think it will need RemoteEvent for player Inputs
so the player's Character is connected to the player?
yes, any local script can run in one of 5 locations (Backpack, character (SCS), PlayerGui, PlayerScripts and ReplicatedFirst), all of which will have the same local player and listen to the same inputs from UIS
ya
i personally dont have any scripts in the character
I think to make it work the script needs to be in ReplicatedStorage and Clone it everytime the character reapawns?
local Shift = Enum.KeyCode.LeftShift
local UserInputService = game:GetService("UserInputService")
local sprint = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local function sprint(InputType)
if Enum.InputType == Shift then
sprint.Parent.Humanoid.Walkspeed = (16)
end
end
UserInputService.InputBegan:Connect(sprint)```
@pliant fossil add a script in ReplicatedStorage and clone it in character everytime the character respawns
local shift = Enum.KeyCode.LeftShift
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local function setWalkSpeed(speed: number)
-- we first make sure both the character and humanoid exist and then we set the walk speed to the paramter given
local Character = player.Character
if not Character then
return
end
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
if not Humanoid then
return
end
Humanoid.WalkSpeed = speed
end
UserInputService.InputBegan:Connect(function(input, isProcessed)
if input.KeyCode == shift then
setWalkSpeed(32)
end
end)
UserInputService.InputEnded:Connect(function(input, isProcessed)
if input.KeyCode == shift then
setWalkSpeed(16)
end
end)
there is no need to overcomplicate things
thanks icy
np
i tried to not spoonfeed you but i gotta go to sleep
good luck and have fun!
it doesnt get easier but it gets more fun
@pliant fossil I'll eat so wait me I'll make the code
wait I'll remake the code
what does the Humanoid.WalkSpeed = speed do? sorry if you still away
ke
put this script in StarterCharacterScripts
local character = script.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local UIS = game:GetService("UserInputService")
local function walk()
humanoid.WalkSpeed = 16
end
local function sprint()
humanoid.WalkSpeed = 30
end
UIS.InputBegan:Connect(function(input, isProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
sprint()
end
end)
UIS.InputEnded:Connect(function(input, isProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
walk()
end
end)
put this script in StarterCharacterScripts
local character = script.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local UIS = game:GetService("UserInputService")
local function walk()
humanoid.WalkSpeed = 16
end
local function sprint()
humanoid.WalkSpeed = 30
end
UIS.InputBegan:Connect(function(input, isProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
sprint()
end
end)
UIS.InputEnded:Connect(function(input, isProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift then
walk()
end
end)
Speed is a parameter you are sending to the function, so when you do setWalkSpeed(16) speed will be equal to 16 since it's the parameter you are sending
what if i dont add that?
@pliant fossil
the Humanoid.WalkSpeed = speed
Then the function won't do anything?
I am assuming you'll remove the entire line
Which is all the code that is inside the function
if you don't add Humanoid.WalkSpeed = speed , the speed will be the same
so do i set the speed as what i want it to or what it already is?
you can set it if you want even 10000
This is a visual representation of what happens to the numbers you have in the ()
Speed becomes those numbers
ohh