#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)

dire condor
#

nothing, just that u didnt connect the func to the actual UIS event

pliant fossil
#

how do i do that

#

i usally build sorry not to sure about alot of thing

#

s

dire condor
#

UserInputService.InputBegan:Connect(sprint)

#

but u would use

#

Enum

#

if Enum.UserInputType == Shift then

pliant fossil
#

alright thanks bro

dire condor
#

Enum.KeyCode.LeftShift i think

pliant fossil
#

ohh

dire condor
#

and u should do

#

if input.KeyCode == Enum.KeyCode.LeftShift then
...
end

pliant fossil
#

i have the script in starter player is that alright? or would that mess soemthign up

dire condor
#

yes, it needs to be a localscript and having it in starterplayerscripts is good, so only run when the player is loaded

pliant fossil
#

alright

dull notch
#

don't create the function inside the UIS event, instead put it outside before the event and call it using the UIS event

fiery kelpBOT
#

studio** You are now Level 7! **studio

pliant fossil
#

what is a UIS event?

#

nvm

#

im acutally sped

dull notch
dull notch
#

and the rest

pliant fossil
#

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

dull notch
#

wait I'll remake your code

pliant fossil
#

alright

dull notch
#
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)
dull notch
#

@pliant fossil

pliant fossil
#

damn that js made it so much more complicated than id think 😭

dull notch
#

yeah but I think it works

#

I have made a game with Sprint

pliant fossil
#

alright im gunna try to use your code and work it into what i made i dont like blatenly copieying

hexed grove
#

no it will not work

pliant fossil
#

so ill let yk when it works

hexed grove
#

for multiple reasons

dull notch
#

whyM

hexed grove
#
  1. there is a flipped bracket, 2 the parent of the script is not the player object but rather PlayerScripts
dull notch
#

the local script is on StarterPlayerScripts

hexed grove
#

yes..

#

which is then parented to playerscripts in player on runtime

dull notch
#
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)
hexed grove
#

also im 99% sure this breaks when you respawn

dull notch
#

wait

hexed grove
#

yes it doesnt work when you respawn

#

because Character points to nil now

pliant fossil
#

icy

hexed grove
#

sup bro

dull notch
#

just replace the player path to game.Players.LocalPlayer

pliant fossil
#
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
dull notch
#

the player path is wrong

#

and the locaCharacterWalkSpeed

hexed grove
#

player.Parent.locaCharacterWalkSpeed isnt a real thing

pliant fossil
#

did not mean to type that

#

js realized

#

yeah still doenst work when i fix it

dull notch
#

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)
hexed grove
#

you need to change humanoid.WalkSpeed instead

hexed grove
#

again, it breaks when you respawn

dull notch
#

why?

#

@pliant fossil remake your code or mine but in StarterCharacterScripts

hexed grove
#

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

dull notch
#

yeah so it needs to remake and put in StarterCharacterScripts

#

but I think it will need RemoteEvent for player Inputs

hexed grove
#

what??

#

you can have local scripts in SCS just fine and access UIS from there

dull notch
#

so the player's Character is connected to the player?

hexed grove
#

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

dull notch
#

ya

hexed grove
#

i personally dont have any scripts in the character

dull notch
#

I think to make it work the script needs to be in ReplicatedStorage and Clone it everytime the character reapawns?

pliant fossil
#
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)```
dull notch
#

bruh

#

wait

pliant fossil
#

@hexed grove

#

thast what i did while you guys were yappin

dull notch
#

@pliant fossil add a script in ReplicatedStorage and clone it in character everytime the character respawns

hexed grove
# pliant fossil <@472816569043648513>
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)
hexed grove
pliant fossil
#

thanks icy

hexed grove
#

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
#

alrightt goodnight thanks bro

#

thank you too sky

dull notch
#

@pliant fossil I'll eat so wait me I'll make the code

dull notch
#

wait I'll remake the code

pliant fossil
#

ke

dull notch
#

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)
hexed grove
hexed grove
#

What do you mean?

#

?!

pliant fossil
#

the Humanoid.WalkSpeed = speed

hexed grove
#

Then the function won't do anything?

pliant fossil
#

oh

#

alright

hexed grove
#

I am assuming you'll remove the entire line

#

Which is all the code that is inside the function

dull notch
#

if you don't add Humanoid.WalkSpeed = speed , the speed will be the same

pliant fossil
dull notch
#

you can set it if you want even 10000

hexed grove
#

Speed becomes those numbers

pliant fossil
#

ohh

hexed grove
#

You can see the similarity as in when you are declaring the function it's setWalkSpeed(speed) and when you call it setWalkSpeed(16)

#

Oh and that :Number is just for type declaration you dont need to add it

#

You can just have setWalkSpeed(speed)