So I made a script that automatically assigns certain objects to specific locations.
The local script gets cloned to playerGui while the server script is then cloned to server storage.
The remote event that will be used will not be cloned and is in Replicated Storage.
For some reason, After cloning the objects, the local script does fire the event while the cloned server script with OnServerEvent won’t even work.
The objects get cloned to each player by using game.Players.PlayerAdded. Take note that the scripts are originally disabled to prevent it from working. It’ll only get enabled when It’s already cloned to their specific location.
I will be showing you the clips as well as scripts to visualize what I meant.
local Script
local StartRemote = replicatedStorage:WaitForChild("RemoteFold").Remote1
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.C then
print("KEYDOWN")
StartRemote:FireServer()
end
end)
Server Script and the Script that will clone the objects
Server Script (The one that will catch the event fired by the cloned local script)
local Remote = replicatedStorage:WaitForChild("Modes").Remote1
Remote.OnServerEvent:Connect(function(Player)
print("Fired The remote!")
end)
Clone Handler (The script that will clone the object to their locations)
local MainScript = script.Parent.MainScript
local SubScript = script.Parent.UIS
local SStorage = game:GetService("ServerStorage")
local PlayerDataFolder = SStorage:WaitForChild("PlayerData")
game.Players.PlayerAdded:Connect(function(Player)
local UserId = Player.UserId
local ClonedScript = MainScript:Clone()
ClonedScript.Parent = PlayerDataFolder:WaitForChild(UserId):WaitForChild("Modes")
ClonedScript.Disabled = false
local ClonedLocalScript = SubScript:Clone()
ClonedLocalScript.Parent = Player:WaitForChild("PlayerGui")
ClonedLocalScript.Disabled = false
end)
First Video
This video shows that the scripts have been successfully cloned to their location.
Notice that when I press the assigned key bind it does print “KEYDOWN” which indicates that it’s successfully working and detecting player input and has also fired the remote. However, the serverscript at Server Storage won’t catch the fired remote.
It should’ve also printed “Fired The remote!” which should work when the OnServerEvent worked but It didn’t.