pretty sure this is the 80th time ive gotten an error while making my tds game
So basically, im trying to pass the tower being placed through a remote event to see what tower to clone.
but im getting an error:
here is the client sided code:
local player = game.Players.LocalPlayer
local Character = player.Character
local HRP = player.Character:WaitForChild("HumanoidRootPart")
local Mouse = player:GetMouse()
local renderingPath
local placingPath
local canPlace = false
local isPlacing = false
local rendering = game:GetService("RunService")
local Towers_ = script.Parent.InventoryBar:GetChildren()
for _, towerPicked in pairs(Towers_) do
towerPicked.MouseButton1Click:Connect(function()
local clientTowerPreview = towerPicked.Tower:Clone()
clientTowerPreview.Parent = workspace
Mouse.TargetFilter = clientTowerPreview
renderingPath = rendering.RenderStepped:Connect(function()
clientTowerPreview.LeftFoot.CFrame = CFrame.new(Mouse.Hit.X, Mouse.Hit.Y, Mouse.Hit.Z)
end)
placingPath = game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.MouseButton1 and canPlace == true then
local CurrPos_ = clientTowerPreview.HumanoidRootPart.CFrame
renderingPath:Disconnect()
placingPath:Disconnect()
clientTowerPreview:Destroy()
game.ReplicatedStorage.TowerPlaced:FireServer(CurrPos_, clientTowerPreview)
elseif canPlace == false then return
end
end
end)
end)
end
server code:
game.ReplicatedStorage.TowerPlaced.OnServerEvent:Connect(function(player, CurrPos_, clientTowerPreview)
local finalTowerPlaced_ = game.ReplicatedStorage.Tower:Clone()
finalTowerPlaced_.HumanoidRootPart.CFrame = CurrPos_
finalTowerPlaced_.Parent = workspace
print(clientTowerPreview.HumanoidRootPart.Position) --Gives an erroor
end)
Thanks in advance