Attempt to index nil with 'Transparency'

so im trying to make a tower placement system for my tower defense game. but when firing a remote event when the mouse is clicked so that the tower appears on both client and server, i keep getting the error:

Attempt to index nil with 'Transparency'

i dont really understand what it means.

here is the code on the client (also the full script is much bigger but this is the part where it fires the remote event):

if Mouse.Target == workspace.Placeable then
	if currentdecoy == nil then
        currentdecoy = nil
		isSpawining = false

here is the code on the server:

local event = game.ReplicatedStorage:WaitForChild("SpawnTower")
       print(player.Name.. " has spawned a tower")
       currentdecoy.Transparency = 0

do remote function instead of remote event as remote event, right after you fired the event the current decoy becomes nil so you indexed nil with transparency

ive done stuff with remote events, but i dont know how remote functions work tho

i tried using a remote function, it still gave out the same exact error, i even tried removing the line that made currentdecoy nil

came back from dinner
what is current decoy though, u never set it as variable

currentdecoy is set to spawndecoy() which is a function which spawns a decoy and then returns the decoy as a value

and the code for the spawndecoy() function is:

function spawnDecoy()

local decoy = game.ReplicatedStorage.Towers.Tower:Clone()

decoy.Parent = workspace

decoy.Transparency = .5

decoy.CanCollide = false

decoy.Position = Mouse.Hit.p +,1,0)

return decoy


wheres the current decoy variable, can you give me the line where you said like

currentdecoy = ....

this is the line where i set the currentdecoy:

currentdecoy = spawnDecoy()

the currendecoy = nil and
right after you fired the event do


it printed


and thats what the tower im trying to place is

run the game
ok now right after u put the

decoy.Parent = workspace

check your explorer to see if it exist
and do the fireserver and see if it is there
see if it really is nil

so i did and i saw that the decoy was a parent of workspace.

parent of workspace or children of workspace ;-;

the currentdecoy is a child of workspace.

do currentdecoy appear in server or only in client?

currentdecoy only appears in the client, is that why?

bruh u should have told me that
the server cant see whats in the client
just do currentdecoy.Transparency = 1 in client script u dont need a remote event

but i need to make the tower also appear in the server

also on the client it prints “Tower” but on the server it prints “nil”

I think that variables in functions can’t have a propety, It’s on your ServerSide script