Hello fellow devs! I am creating a td game and I have picked up on client sided rendering, So for my troop system the server will make the troop attack and damage the troop and the client is supposed to render the bullet.For this I tried using fastCast, But i havent figured out how to make the client know the server fired a ray.
I also want some help to see if I am making the troop system efficiently
Module Script:
function attacks.towerAttack(tower)
while tower.Parent == workspace.Towers.Spawned do
task.wait(tower:GetAttribute("Cooldown"))
local target = bestTarget(tower)
if target then
tower:GetAttribute("Target", target)
-- workspace.Towers.Spawned[tower.TowerHash].PrimaryPart.CFrame = CFrame.new(tower.CFrame.Position, Vector3.new(workspace.Enemies.Active[target.EnemyHash].PrimaryPart.Position.X ,tower.CFrame.Position.Y, workspace.Enemies.Active[target.EnemyHash].PrimaryPart.Position.Z))
local enemies = game.ReplicatedStorage:WaitForChild("Events").getEnemies:Invoke()
if enemies[target.EnemyHash] == nil then continue end
local direction = (enemies[target.EnemyHash]["CFrame"].Position - tower.Position).Unit
cast:Fire(tower.Position + Vector3.new(0, 3, 0), direction, 150, behaviour)
enemies[target.EnemyHash]["Health"] -= tower:GetAttribute("Damage")
if enemies[target.EnemyHash]["Health"] <= 0 then
enemies[target.EnemyHash]["Dead"] = true
end
local result = game.ReplicatedStorage:WaitForChild("Events").getEnemies:Invoke(enemies)
--tower.TotalDamage += tower:GetAttribute("Damage")
end
end
return
end
The server script:
placingEvent.OnServerEvent:Connect(function(plr, tower, placer, name, hash)
local off = replicated.Towers:FindFirstChild(name)
plr.Cash.Value -= off.Price.Value
local part = Instance.new("Part")
part.Name = name
part.Parent = workspace.Towers.Spawned
part.BrickColor = BrickColor.new("Really red")
part.Size = Vector3.new(1,0,1)
part.CFrame = tower
part:SetAttribute("Damage", towerdb[name].Damage)
part:SetAttribute("Cooldown", towerdb[name].Cooldown)
part:SetAttribute("Range", towerdb[name].Range)
part:SetAttribute("CFrame", part.CFrame)
part:SetAttribute("Mode", "First")
part:SetAttribute("Target", " ")
part:SetAttribute("TowerHash", hash)
placingEvent:FireAllClients(placer, part, name)
attacks.towerAttack(part)
end)
I tried using length changed but it isnt firing for some reason, Any help?