Hello
My script based on keydown event When i press E on keyboard a number value in workspace need to change.
plr = game.Players.LocalPlayer Mouse = plr:GetMouse() Mouse.KeyDown:connect(function(key) if key == "e" then game.Workspace.NumberValue.Value = 1 end end)
It's works in studio with Filter enabled, but when i wanna try this in roblox it's Doesn't work, when i press E in game, this doesn't change value, also by enter this command in Developer console
print(game.Workspace.NumberValue.Value)
Developer console show the old number, so this doesn't change.
Any help?
KeyDown
event of Mouse
is deprecated, so is :connect()
. May I introduce you to ContextActionService
:ChangeNumberEvent
is a RemoteEvent
inside of ReplicatedStorage
local rep = game:GetService"ReplicatedStorage" local changeNumEvent = rep:WaitForChild"ChangeNumberEvent" function changeNum() changeNumEvent:FireServer(5) --In between the brackets, put any number end game:GetService("ContextActionService"):BindAction( "NumberChanger", changeNum, false, Enum.KeyCode.E )
local rep = game:GetService"ReplicatedStorage" local changeNumEvent = rep:WaitForChild"ChangeNumberEvent" changeNumEvent.OnServerEvent:Connect(function(plr, value) game.Workspace.NumberValue.Value = value end)