Why is localscript not running when I enable it in serverscript?

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 
    return found

    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

-- 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.

1 Like

My guy, I never said it was in ServerScriptService. It is in StarterPlayer.StarterPlayerScripts and it still doesn’t seem to work.


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.

[Live] Script RunContext - Updates / Announcements - Developer Forum | Roblox


No, I just said the ServerScript enabling LocalScript is in ServerScriptService and the LocalScript is in StarterPlayer.StarterPlayerScripts

1 Like

The client does not replicate any localscripts to the server, so the server doesn’t have any access to localscripts.

1 Like

StarterPlayerScripts doesn’t exist in server because it’s created locally.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.