so whenever a player presses w key it should fire an event and then it should take away .1 from value every time player presses w

local uis = game:GetService("UserInputService")
local debounce = true
local m = game.Players.LocalPlayer:GetMouse()

uis.InputBegan:Connect(function(key,gpe)
	if Enum.KeyCode.W then
		if debounce == true then
			debounce = false
		print("event fired") 
		game.ReplicatedStorage.WMouseDown:FireServer(Enum.KeyCode.W,script.Parent.stam.Stamina.Value)
		wait(1)
		debounce = true
		end
	end
end)

thats localscript. This is server script

game.ReplicatedStorage.WMouseDown.OnServerEvent:Connect(function(player,key,staminavalue)
	staminavalue = staminavalue - 1
	if staminavalue == 80 then
		player.Humanoid.Walkspeed = 15.8
	if staminavalue == 60 then
		player.Humanoid.Walkspeed = 15.6
	if staminavalue == 40 then
		player.Humanoid.Walkspeed = 15.4
	if staminavalue == 20 then
		player.Humanoid.Walkspeed = 15
	if staminavalue == 0 then
		player.Humanoid.Walkspeed = 14
	end
	end
	end
		end
	end
end)

6 comments

0

Check output for errors is step 1

0

there are no errors

0

It's possible that the server can't access what the client calls script.Parent.stam.Stamina, where is the local script located?

0

You didn't check if the input was the W key correctly. You need to replace line 6 in the LocalScript with "if key.KeyCode == Enum.KeyCode.W then". Also, you don't need to use "if debounce == true then" on line 7 of the LocalScript. You can just use "if debounce then". If you wanted to check if debounce was false, you'd use "if not debounce then".

0

You should also check if the player is chatting or not. You can do this by adding the following after line 5: "if gpe then return end". Also, in the server script, please use elseif rather than many unnecessary if statements. This eliminates the need for many ends and is meant for situations like this.

0

it doesn't remove 1 from the number value