- What do I want to achieve?
- I want the client to spawn the tower by clicking a button or pressing a number based on their order.
- What is the issue?
- For some reason, everything was working perfectly earlier. Now this remote function stopped working randomly and it isn’t calling for a return, it seems that the function in the ModuleScript doesn’t want to receive the remote’s call.
- What solutions have I tried so far?
- I’ve tried to change some variables to see if I miss spelled something, it seems that everything is correctly spelled because I haven’t changed anything inside the spawn tower function before this problem occurred.
- I asked to other devs in a discord group which they made a tutorial about how to make a tower defense game, they didn’t understand the mistake and couldn’t help me.
- Anything important you should know?
- Yes, basically all the rest of the game is working; mobs spawning, waves, time, loaded map, etc. All except the tower spawn.
- There are no errors in the output, but the line provoking this issue is the:
local allowedToSpawn = requestTowerFunctions:InvokeServer(Defender.Name)
You will see this line here in the Local Script to see what I mean:
Local Script:
local requestTowerFunctions = functions:WaitForChild("RequestSpawn")
local getDataFunc = functions:WaitForChild("GetData")
local playerData = getDataFunc:InvokeServer()
for i, tower in ipairs(playerData.SelectedDefenders) do
local Defender = towers:FindFirstChild(tower)
if Defender then
local button = gui.MainBar.Content.Defenders.Template:Clone()
local config = Defender:WaitForChild("Config")
local profile = Defender:WaitForChild("Profile")
local statistics = Defender:WaitForChild("Stats")
button.Name = Defender.Name
button.Icon.Image = profile.Icon.Texture
button.DefenderTag.Text = i
button.Price.Text = "$" .. config.Price.Value
button.Price.Visible = true
button.Tag.Value = i
button.Visible = true
button.Parent = gui.MainBar.Content.Defenders
button.Interact.Activated:Connect(function()
local allowedToSpawn = requestTowerFunctions:InvokeServer(Defender.Name)
if allowedToSpawn then
AddPlaceholderTower(Defender.Name)
end
button.SelectionEffect.Visible = true
TweenService:Create(button.SelectionEffect, TweenInfo.new(0.2), {Size = UDim2.new(1.3, 0,1.3, 0)}):Play()
TweenService:Create(button.SelectionEffect, TweenInfo.new(0.2), {BackgroundTransparency = 1}):Play()
task.wait(0.2)
button.SelectionEffect.Visible = false
TweenService:Create(button.SelectionEffect, TweenInfo.new(0), {Size = UDim2.new(1, 0,1, 0)}):Play()
TweenService:Create(button.SelectionEffect, TweenInfo.new(0), {BackgroundTransparency = 0}):Play()
end)
UserInputService.InputBegan:Connect(function(input, processed)
if processed then
return
end
if input.KeyCode.Value == button.Tag.Value + 48 then
local allowedToSpawn = requestTowerFunctions:InvokeServer(Defender.Name)
if allowedToSpawn then
AddPlaceholderTower(Defender.Name)
end
button.SelectionEffect.Visible = true
TweenService:Create(button.SelectionEffect, TweenInfo.new(0.2), {Size = UDim2.new(1.3, 0,1.3, 0)}):Play()
TweenService:Create(button.SelectionEffect, TweenInfo.new(0.2), {BackgroundTransparency = 1}):Play()
task.wait(0.2)
button.SelectionEffect.Visible = false
TweenService:Create(button.SelectionEffect, TweenInfo.new(0), {Size = UDim2.new(1, 0,1, 0)}):Play()
TweenService:Create(button.SelectionEffect, TweenInfo.new(0), {BackgroundTransparency = 0}):Play()
end
end)
end
end
ModuleScript Function:
function tower.CheckSpawn(player, name, previous)
print(name)
local towerExists = ReplicatedStorage.Towers:FindFirstChild(name, true)
if towerExists then
if towerExists.Config.Price.Value <= player.Coins.Value then
if previous or player:WaitForChild("TowersPlacesLimit"):FindFirstChild(towerExists.Profile.DefenderName.Value).Placements.Value < player:WaitForChild("TowersPlacesLimit"):FindFirstChild(towerExists.Profile.DefenderName.Value).Limit.Value then
if previous or player.PlacedDefenders.Value < workspace.Info.MaxDefenders.Value then
return true
else
maxDefendersReached:FireClient(player)
warn("Max Limit of Defenders reached!")
end
else
maxLimitReached:FireClient(player)
warn("Defender has reached max limit")
end
else
cantAfford:FireClient(player)
warn("Player cannot afford")
end
else
warn("Defender does not exist")
end
return false
end
requestTowerFunctions.OnServerInvoke = tower.CheckSpawn
This is the tutorial I watched to make this game:
How to make a Tower Defense Game - #1 Path Navigation - YouTube
I made a lot of effort to make this game, even hired someone to help me on art. I will not waste my project for one error that breaks the important function of this tower defense game. I assume this is a silly mistake since its only one line, but I haven’t found a solution, it’s been 2 days, can anybody help me please? Thank you very much.