Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this not change the value of number value?

Asked by 5 years ago

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)
0
Check output for errors is step 1 gullet 471 — 5y
0
there are no errors WillBe_Stoped 71 — 5y
0
It's possible that the server can't access what the client calls `script.Parent.stam.Stamina`, where is the local script located? Vulkarin 581 — 5y
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". lunatic5 409 — 5y
View all comments (2 more)
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. lunatic5 409 — 5y
0
it doesn't remove 1 from the number value WillBe_Stoped 71 — 5y

Answer this question