im making a tower defense game and while making the upgrade system, the placeholder tower remains after placing until you attempt to place it on an invalid space
when the remotefunction is invoked and placingtowers = true, the code below wont run
these are snippets from the code
the part that isnt working is the “placingTowers” variable
if canplace then --this part is in a localscript
local placingTowers = SPAWNTHETOWER:InvokeServer(towertospawn.Name,towertospawn.PrimaryPart.CFrame) -- this is the part that wont work
if placingTowers then
placedtowers += 1
gui.towers.Parent.counter.Text = placedtowers .."/".. maxtowers
RemoveplaceholderTower()
toggleTowerinfo()
end
end
GETTHETOWER.OnServerInvoke = tower.Spawn --this part is in a modulescript
Yes, it should. A RemoteFunction is a function. You cant connect a function to a function. But you can try printing to see if your canplace variable is even true.
if canplace then
local placedTower = SPAWNTHETOWER:InvokeServer(towertospawn.Name,towertospawn.PrimaryPart.CFrame)
print(placedTower)
if placedTower then
placedtowers += 1
gui.towers.Parent.counter.Text = placedtowers .."/".. maxtowers
toggleTowerinfo()
end
end
this is what is supposed to run
but it wont print anything unless placedTowers is false
Ok now i understand. It looks like in the line where you invoke the server it goes in a loop.
In your remote function try to not only exute the code but also at the and a return true
nil and ‘scour’ are the towers you are trying to place
‘poor’ and ‘tower is not real’ happen when you dont have enough money
true is placedTower’s value and despite being true, the code will not run
placedTower wont print until you run out of money or some other placement error