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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
Thank you! pmainokiborg 6 — 5y
0
Where should i need to put first script? pmainokiborg 6 — 5y
0
Under StarterGui, StarterPack, ot StarterPlayerScripts User#19524 175 — 5y
Ad

Answer this question