I don't know why my script don't work

someone can help me i don’t know why player speed is not changing on crouch

Script in ServerScriptService


local ReplicateStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicateStorage:WaitForChild("Remotes")

local Events = Remotes:FindFirstChild("Events")

local Mechanics = Events:FindFirstChild("Mechanics")
local Surviving = Events:FindFirstChild("Surviving")

local RespawnPosition = game.Workspace:WaitForChild("Respawn").RespawnPoint

Surviving.Died.OnServerEvent:Connect(function(player,reason)
	
	print(player.Name .. " died by " .. reason)
	
	player.CharacterAdded:Connect(function(character)
		
		repeat wait() until character.HumanoidRootPart
		
		character.HumanoidRootPart.CFrame = RespawnPosition.CFrame
		
	end)
end)

Mechanics.Crouch.OnServerEvent:Connect(function(player)
	
	print(player.Name .. " Crouched")
	
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").WalkSpeed = 8
	end)
end)

LocalScript in StarterGui

local Player = game.Players.LocalPlayer

local InputServ = game.UserInputService

local Mechanics = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):FindFirstChild("Events").Mechanics

InputServ.InputBegan:Connect(function(input)
	if (InputServ:GetFocusedTextBox()) then
		return; -- make sure player's not chatting!
	end
	if input.KeyCode == Enum.KeyCode.C  or input.KeyCode == Enum.KeyCode.LeftControl then
		Mechanics.Crouch:FireServer()
		return
	end	
	if input.KeyCode == Enum.KeyCode.V  or input.KeyCode == Enum.KeyCode.LeftAlt then
		Mechanics.Crawl:FireServer()
		return
	end	
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Mechanics.Sprint:FireServer()
		return
	end	
end)
1 Like

Your current crouch code changes the walkspeed of the player when the player respawns. If you want to change it for the player’s current character, this should do that.

Mechanics.Crouch.OnServerEvent:Connect(function(player)
	
	print(player.Name .. " Crouched")
	
	local character = player.Character or player.CharacterAdded:Wait()
	character:WaitForChild("Humanoid").WalkSpeed = 8
end)
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.