Why is this LocalScript not running when I enable it in a ServerScript? The local script runs perfectly separately so idk why this is happening. When loaded in the game, its shown the localscript gets enabled so idk why the script doesn’t run.
-- LocalScript
local replicatedStorage = game:GetService('ReplicatedStorage')
local UserInputService = game:GetService('UserInputService')
local flyingEvent = replicatedStorage.Broom.FlyingEvent
function includes(array, x)
local found = false
for _, v in array do
if v == x then
found = true
end
end
return found
end
UserInputService.InputBegan:Connect(function(input)
print(input.KeyCode)
print(includes(table, input.KeyCode))
local array = { Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D, Enum.KeyCode.LeftShift, Enum.KeyCode.LeftControl }
if not includes(table, input.KeyCode) then return end
flyingEvent:FireServer(input.KeyCode)
end)
-- Server Script
localScript.Enabled = true
My guy local scripts don’t run in ServerScriptService because local scripts are suppose to be local to the player and not the server. Put it in the StarterPlayer.StarterPlayerScripts folder so the local script is replicated to the player each time they join the game.
If you mean that you have a localscript parented to a script, it wont run. its context action is based off its parent and if the parent has a server-sided reference, it wont run. There is a beta feature that allows you to change the RunContext of scripts, meaning you can make them run from anywhere.