Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how to change walkspeed in this script when crouching???

So i made a crouch script that makes you crouch. i got a idle animation as well when you aren't walking. i know how to change walkspeed but not where to put it in this script. Can somebody help me?

Here is the script:

ps i have a RemoteEvent that is named "OnCrouchBegun"

local uis = game:GetService("UserInputService")

local crawlAnimation = script:WaitForChild("Crawl")
local loadedCrawlAnim

local crawlIdle = script:WaitForChild("CrawlIdle")
local loadedIdleAnim

local isCrawling = false

local humanoid = script.Parent:FindFirstChild("Humanoid")


uis.InputBegan:Connect(function(key, gameProcessed)

	if key.KeyCode == Enum.KeyCode.C then
		
		game.StarterPlayer.CharacterWalkSpeed = 5

		if isCrawling then

			isCrawling = false  

			if loadedCrawlAnim then loadedCrawlAnim:Stop() end  

			loadedIdleAnim:Stop()           

			game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 16, 50)

		elseif not isCrawling then
			


			isCrawling = true   

			loadedIdleAnim = humanoid:LoadAnimation(crawlIdle)
			loadedIdleAnim:Play()

			game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 3, 20)
		end
	end 
end)


game:GetService("RunService").RenderStepped:Connect(function()

	if not isCrawling then return end

	if humanoid.MoveDirection.Magnitude > 0 then

		if not loadedCrawlAnim then loadedCrawlAnim = humanoid:LoadAnimation(crawlAnimation) end
		if loadedCrawlAnim.IsPlaying == false then loadedCrawlAnim:Play() end   

	else
		
		loadedCrawlAnim:Stop()
		loadedIdleAnim:Play()
	end
end)

4 comments

0

You have to change the WalkSpeed property of Humanoid on the Server.

0

wait what?

0

You should add a remote event that triggers an event on the server then the server sets that players walk speed this is would @Ziffixture tired to explain fast

0

do humanoid.WalkSpeed

1 answer

Rather than writing it as:

game.StarterPlayer.CharacterWalkSpeed = 5

instead do (in the server script):

player.Character.humanoid.Walkspeed = 5

Use a remove event that fires when you would normally have the speed change that goes into a local script. If you need to learn how they work this website will help. https://www.google.com/search?client=firefox-b-1-d&q=Roblox+Studio+Remote+events

Make sure you change this for the crawl, crouch, and when you go back to standing. Also, Make sure that it is in a Server Script. If this answered your question be sure to accept it. If something is the wrong comment and I'll try and figure it out.

1 comment

0

well im bad at remote events like that. can u like type where i should put things?

This discussion is preserved as it was. New answers, comments, and votes are closed.