Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Filter enabled - local script doesn't want to change NumberValue in workspace?

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?

1 answer

✓ Accepted answer

###The 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
)

###Server code:

local rep = game:GetService"ReplicatedStorage"
local changeNumEvent = rep:WaitForChild"ChangeNumberEvent"

changeNumEvent.OnServerEvent:Connect(function(plr, value)
    game.Workspace.NumberValue.Value = value 
end)

3 comments

0

Thank you!

0

Where should i need to put first script?

0

Under StarterGui, StarterPack, ot StarterPlayerScripts

This discussion is preserved as it was. New answers, comments, and votes are closed.