Hello Developers, I Have Created A Tower System For My TD Game But I Got A Problem Soo When I Place A Tower I Am The Only One That See’s That Tower I Know What You Are Thinking “Make The Towers Server Sided” I Can’t Bc My Mobs Are Client Sided Here Is My Code Logic Client Sided Module :
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
--Events handler
local Events_Folder = ReplicatedStorage:WaitForChild("RemotesFolder")
--Tower Events
local Tower_Events = Events_Folder:WaitForChild("Tower_Events")
local OnClient = Tower_Events:WaitForChild("OnClient")
local OnServer = Tower_Events:WaitForChild("OnServer")
local Camera = game.Workspace.CurrentCamera
local Tower = {}
function Tower.Spawn(SelectedTower, BlackList)
local RP = RaycastParams.new()
RP.FilterType = Enum.RaycastFilterType.Exclude
RP.FilterDescendantsInstances = BlackList
local MouseLoc = UIS:GetMouseLocation()
local Direction = Camera:ViewportPointToRay(MouseLoc.X, MouseLoc.Y)
local RayResult = workspace:Raycast(Direction.Origin, Direction.Direction * 100, RP)
if RayResult then
local part = Instance.new("Part")
part.Anchored = true
part.Position = RayResult.Position
part.Parent = workspace
part.Name = SelectedTower
print("Part created")
else
print("Mouse is nil")
end
end
OnClient.OnClientEvent:Connect(Tower.Spawn)
function Tower.SpawnOnClient(SelectedTower, BlackList)
OnServer:FireServer(SelectedTower, BlackList)
end
return Tower
client side local script:
--client tower module local script handler :
-- Services
local UIS = game:GetService("UserInputService")
-- require
local Tower_Module = require(script.Parent.Parent.Tower_Module:WaitForChild("Tower_Module"))
-- Variables
local SelectedTower = nil
script.Parent.Parent.Parent.Gui.Gui.SELECTGUI.Test.Activated:Connect(function()
SelectedTower = "String"
end)
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and SelectedTower then
Tower_Module.SpawnOnClient(SelectedTower, {})
end
end)
server side module :
--Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Events handler
local Events_Folder = ReplicatedStorage:WaitForChild("RemotesFolder")
--Tower Events
local Tower_Events = Events_Folder:WaitForChild("Tower_Events")
local OnClient = Tower_Events:WaitForChild("OnClient")
local OnServer = Tower_Events:WaitForChild("OnServer")
local Tower = {}
function Tower.Spawn(player, SelectedTower, BlackList)
OnClient:FireAllClients(SelectedTower, BlackList)
end
OnServer.OnServerEvent:Connect(Tower.Spawn)
return Tower
server side script:
--require
local Tower_Module = require(script.Parent.Parent.Tower_Module:WaitForChild("Tower_Module"))
any helps is appreciated!