I was making a game where a 3d box moves into an outline and you have to press a certain key to hit the 3d box. It works perfectly using the Play button in roblox studio, but when I use a server, everything just stops working correctly. On the server screen, nothing is moving; but on the client screen, things are moving but input is completely ignored, as if these were two different programs.
Problem I noticed that local scripts only edit Clientside Workspace, which is the workspace that appears for you, which I found odd because usually it does not do this. It works if I change it to a global script, but I still cannot access keyboard input without using a local script. I tried using boolvalues that the local script would set true and the global script would detect so that it would run the functions for them but, as stated earlier, the local script affects the Clientside Workspace not the Server Workspace, so the values appeared true on the client screen but appeared false on the server screen.
Question How do I make functions that affect the Server Workspace when pressing a key on the keyboard?
global script -- used to do global work for localscript
wait(0.5)
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "keyXpressed"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key0pressed"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key1pressed"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key2pressed"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key3pressed"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key4pressed"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key5pressed"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key1lifted"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key2lifted"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key3lifted"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key4lifted"
Instance.new("BoolValue", script.Parent.GuitarKeyScript).Name = "key5lifted"
print("valuesmade")
while true do
if script.Parent.GuitarKeyScript.keyXpressed.Value == true then
script.Parent.GuitarKeyScript.keyXpressed.Value = false
if game.Workspace.Guitar.Overdrive.Value >= 50 then
game.Workspace.Guitar.Overdrived.Value = true
end
end
end
local script -- used to detect key presses on keyboard
wait(1)
local mouse = game.Players:FindFirstChild(script.Parent.Name):GetMouse()
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera:Interpolate(game.Workspace.Head.CFrame,game.Workspace.Head2.CFrame,0.5)
script.Parent.Humanoid.WalkSpeed = 0
local keyX = "j"
local key0 = "k"
local key1 = "q"
local key2 = "w"
local key3 = "e"
local key4 = "r"
local key5 = "t"
function press(key)
key = string.lower(key)
if key == keyX then
script.keyXpressed.Value = true
end
if key == key0 then
script.key0pressed.Value = true
elseif key == key1 then
script.key1pressed.Value = true
elseif key == key2 then
script.key2pressed.Value = true
elseif key == key3 then
script.key3pressed.Value = true
elseif key == key4 then
script.key4pressed.Value = true
elseif key == key5 then
script.key5pressed.Value = true
end
end
function lift(key)
key = string.lower(key)
if key == key1 then
script.key1lifted.Value = true
elseif key == key2 then
script.key2lifted.Value = true
elseif key == key3 then
script.key3lifted.Value = true
elseif key == key4 then
script.key4lifted.Value = true
elseif key == key5 then
script.key5lifted.Value = true
end
end
mouse.KeyDown:connect(press)
mouse.KeyUp:connect(lift)

1 comment
You answered your question in the title!