Localscript does not reach remoteevent

Im trying to make a part spawn when i click, on the serverside. I cannot for the life of me be able to contact the remoteevent from the localscript (in starterplayerscripts), or maybe the code in the script parented to the remotevent is wrong. The remoteevent is called CubeSpawn and it’s parented to ReplicatedStorage.

script code:

game.ReplicatedStorage.CubeSpawn.OnServerEvent:Connect(function()
local Newpart = Instance.new("Part")
Newpart.Size = Vector3.new(10, 10 ,10)
Newpart.Parent = workspace
end)

localscript code:

local repliatedstorage = game:GetService("UserInputService")
repliatedstorage.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then	
		game.ReplicatedStorage.CubeSpawn:FireServer()
	end end)

Well I see the problem, you say the Script (Server) is parented to an Instance which is a Descendant of ReplicatedStorage? If so, a Script can not run in a Storage, as the name says it. You may put the script in ServerScriptService to really run the script, the local reaches to Remote, but the script is not getting it, since Storage means basically stored.

1 Like

Thanks! It worked.

this post needs to be thirtie characters long

To clarify for anyone who reads this thread in the future, a Script with the default RunContext value of Legacy cannot run code while in some services, such as:


However, Scripts that have a RunContext value of Server or Client can run in places that wouldn’t typically run when using a default Script or LocalScript.

This means that you could place a Script with a RunContext value of Server or Client into the ReplicatedStorage, and its code would run there. Keep in mind that this does not allow client-sided scripts to run in server containers (such as the ServerStorage).




While it still depends on the use case whether or not you should use a Script with a different RunContext value over a default Script / LocalScript, I wanted to make sure it was clarified that there is a way to run code in places such as the storage services that is only possible because of the addition of the RunContext property.

This encompasses more than just the storage services, too, as it even allows client-sided scripts to run in services like the Workspace without needing to be included in a Character model.

To learn more about RunContext, refer to the Roblox Developer Forum announcement thread that was created for that feature.

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