I am trying to make a gui which should load something into the workspace. the maps are in the replicated storage and the remove event is also in replicated storage.
the two scripts (clientHandler and serverHandler) are placed in a gui btn in StarterGui
here are the scripts Client Handler
loadWep = game:GetService('ReplicatedStorage').client_server_Bridge.loadWep script.Parent.MouseButton1Click:connect(function() loadWep:FireServer() print('fired!') end)
Server Handler
loadWep = game:GetService('ReplicatedStorage').client_server_Bridge.loadMap DM = game.Workspace.DataModel MapHolder = DM.MapHolder w = game.Workspace._W w1 = game.Workspace._W1 mapName = script.Parent.Name function searchMap(name, loc) for k,v in pairs(loc) do if v.Name == name then return v end end end function onClick() local EmptySpace = MapHolder:GetChildren() if #EmptySpace >= 1 then MapHolder:ClearAllChildren() end searchMap(mapName, game.ReplicatedStorage.Maps:GetChildren()):clone().Parent = MapHolder w.Transparency = 0.6 w1.Transparency = 0.6 end loadWep.OnServerEvent:connect(function() onClick() end)
Please help me
Scripts either don't, or under any circumstances shouldn't run under the PlayerGui when FilteringEnabled is active.
You'll need to move your script to ServerScriptService
as was suggested. On a side note, your searchMap
function is redundant:
loadWep = game:GetService('ReplicatedStorage').client_server_Bridge.loadMap DM = game.Workspace.DataModel MapHolder = DM.MapHolder w = game.Workspace._W w1 = game.Workspace._W1 mapName = script.Parent.Name function onClick() local EmptySpace = MapHolder:GetChildren() if #EmptySpace >= 1 then MapHolder:ClearAllChildren() end game.ReplicatedStorage.Maps:FindFirstChild(mapName):Clone().Parent = MapHolder w.Transparency = 0.6 w1.Transparency = 0.6 end loadWep.OnServerEvent:connect(onClick)