My script is somehow confusing

Hey, I’m working on my Tower Defense game, soo I was making a placement system, if players click on a certain Tower on their inventory UI thing they can place down that Tower, I made a signal sender and signal retriever script, and the signal sender will send a remote event signal to signal retriever and of course, the signal retriever will retrieve it and send another remote event signal to Placement System Script and Placement System Script sends another signal to Module Script to place it down

soo the problem is: it didn’t work, it gave me this error: Players.HertsDan.PlayerGui.GameUI.TextButton.Script:13: attempt to index nil with ‘Name’

Here’s my script
Module:

local Towers = {}

local PhysicsService = game:GetService("PhysicsService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TowersFolder = ReplicatedStorage.Towers

local Remotes = ReplicatedStorage:WaitForChild("Remote")
local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")

function Towers.PlaceDown(Player, TowerName, Cframe)
	local WantedTower = Towers:FindFirstChild(TowerName)

	if WantedTower then
		local ClonedTower = WantedTower:Clone()
		ClonedTower.HumanoidRootPart.CFrame = Cframe
		ClonedTower.Parent = workspace.Towers
		ClonedTower.HumanoidRootPart:SetNetworkOwner(nil)

		for i, EveryParts in ipairs(ClonedTower:GetDescendants()) do
			if EveryParts:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(EveryParts, "Towers")
			end
		end
	end
end

PlaceTowerEvent.OnServerEvent:Connect(Towers.PlaceDown)

return Towers

Signal Sender:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage:WaitForChild("Remote")

local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")

local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")

local TowersFolder = ReplicatedStorage:WaitForChild("Towers")

local SignalEvent = script.Parent.Signal

script.Parent.Activated:Connect(function()

SignalEvent:FireServer(script.Parent.Text)

end)

Signal Retriever:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage:WaitForChild("Remote")

local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")

local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")

local TowersFolder = ReplicatedStorage:WaitForChild("Towers")

local SignalEvent = script.Parent.Signal

SignalEvent.OnServerEvent:Connect(function(TowerName)

local ConfirmedTowers = TowersFolder:FindFirstChild(TowerName)

TowerInfoEvent:FireClient(ConfirmedTowers.Name) -- Error here

end)

PlacementSystem (By Gnome Code):

local PhysicsEngine = game:GetService("PhysicsService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local Remotes = ReplicatedStorage:WaitForChild("Remote")
local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")
local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")
local TowersFolder = ReplicatedStorage:WaitForChild("Towers")
local Camera = workspace.CurrentCamera
local Gui = script.Parent

local TowerToSpawn = nil
local CanPlace = false
local Rotation = 0

local function MouseRaycast(Blacklist)
	local MousePos = UserInputService:GetMouseLocation()
	local Mouseray = Camera:ViewportPointToRay(MousePos.X, MousePos.Y)
	local Raycastparams = RaycastParams.new()

	Raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
	Raycastparams.FilterDescendantsInstances = Blacklist

	local RaycastResult = workspace:Raycast(Mouseray.Origin, Mouseray.Direction * 1000, Raycastparams)

	return RaycastResult
end

local function RemovePlaceholder()
	if TowerToSpawn then
		TowerToSpawn:Destroy()
		TowerToSpawn = nil
		Rotation = 0
	end
end

local function AddPlaceholderTower(Name)
	
	TowerInfoEvent.OnClientEvent:Connect(function(TowerName)
		local ExistingTowers = TowersFolder:FindFirstChild(TowerName)
		
		if ExistingTowers then
			RemovePlaceholder()
			TowerToSpawn = ExistingTowers:Clone()
			TowerToSpawn.Parent = workspace.Towers

			TowerToSpawn.Outline.OutlineColor = TowerName
		end
	end)
end

local function ColorPlaceholder(color)
	for i, Object in ipairs(TowerToSpawn:GetDescendants()) do
		if Object:IsA("BasePart") then
			PhysicsEngine:SetPartCollisionGroup(Object, "Tower")
			Object.Color = color
		end
	end
end

TowerInfoEvent.OnClientEvent:Connect(function(Player, TowerName)
	Gui.TextButton.Activated:Connect(function()
		AddPlaceholderTower(TowerName)
	end)
end)

UserInputService.InputBegan:Connect(function(Input, Processed)
	if Processed then
		return
	end

	if TowerToSpawn then
		if Input.UserInputType == Enum.UserInputType.MouseButton1 then
			if CanPlace then
				PlaceTowerEvent:FireServer(TowerToSpawn.Name, TowerToSpawn.PrimaryPart.CFrame)
				RemovePlaceholder()
			end
		elseif Input.KeyCode == Enum.KeyCode.R then
			Rotation += 90
		elseif Input.KeyCode == Enum.KeyCode.Q then
			Rotation -= 90
		end
	end

end)

RunService.RenderStepped:Connect(function()
	if TowerToSpawn then
		local Result = MouseRaycast({TowerToSpawn})
		if Result and Result.Instance then
			if Result.Instance.Parent.Name == "TowersArea" then
				CanPlace = true
				ColorPlaceholder(Color3.fromRGB(255, 255, 255))
			else
				CanPlace = false
				ColorPlaceholder(Color3.fromRGB(255, 0, 0))
			end
			local X = Result.Position.X
			local Y = Result.Position.Y + TowerToSpawn.Humanoid.HipHeight + (TowerToSpawn.PrimaryPart.Size.Y /2)
			local Z = Result.Position.Z

			local Cframe = CFrame.new(X, Y, Z) * CFrame.Angles(0, math.rad(Rotation), 0)
			TowerToSpawn:SetPrimaryPartCFrame(Cframe)
		end
	end
end)

I’m sorry if I waste someone’s time any help is appreciated

1 Like

Which is the Script inside of the TextButton for the GameUI?

1 Like

Signal Retriever and Signal Sender

1 Like

OnServerEvent has the player argument first, then what you sent.

New Signal Retriever

replace Signal Retrieve with this

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remotes = ReplicatedStorage:WaitForChild("Remote")

local PlaceTowerEvent = Remotes:WaitForChild("PlaceTower")

local TowerInfoEvent = Remotes:WaitForChild("TowerInfo")

local TowersFolder = ReplicatedStorage:WaitForChild("Towers")

local SignalEvent = script.Parent.Signal

SignalEvent.OnServerEvent:Connect(function(TowerName)

local ConfirmedTowers = TowersFolder:FindFirstChild(TowerName)

print(ConfirmedTowers)

TowerInfoEvent:FireClient(ConfirmedTowers.Name) -- Error here

end)

and tell us the output

Argument 1 missing or nil on Line 11