So I want it so that when I press E it should add 5 to value. But if i press Q it should take away 5 from value
local UIS = game:GetService("UserInputService")
local tool = script.Parent
UIS.InputBegan:Connect(function(IO)
if IO.KeyCode == Enum.KeyCode.Q then
game.ReplicatedStorage.Events.PowerChangeQ:FireServer(tool,Enum.KeyCode.Q)
if IO.KeyCode == Enum.KeyCode.E then
game.ReplicatedStorage.Events.PowerChangeE:FireServer(tool,Enum.KeyCode.E)
end
end
end)
Local Script
local rep = game.ReplicatedStorage
local maxpower = 120
local minpower = 0
rep.Events.PowerChangeQ.OnServerEvent:Connect(function(player,tool,key)
if key == Enum.KeyCode.Q and tool.Power.Value > minpower then
wait()
tool.Power.Value = tool.Power.Value - 5
wait()
print(tool.Power.Value)
end
end)
rep.Events.PowerChangeE.OnServerEvent:Connect(function(player,tool,key)
if key == Enum.KeyCode.E and tool.Power.Value > maxpower then
wait()
tool.Power.Value = tool.Power.Value + 5
wait()
print(tool.Power.Value)
end
end)
Server Script

1 comment
Why are you checking the key pressed on the server? Never do that.