Script Not Detecting A Object

Im trying to create tower selling for my game im working on which will help me get upgrades to work due to being the same code but changed but for some reason it does not work(doesn’t even disable the ui and event does work fine as it works on things that don’t require clicking)
this is the code

script.Parent.Parent.Parent.Parent.TowerUpgade.Event:Connect(function(tower,towername)
	script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.Parent.Enabled = false
	tower.Sold:Fire()
	
	end)
end)

I just need to know what im doing wrong thats it. Thanks

script.Parent.Parent.Parent.Parent.TowerUpgade.Event, are you trying do something when this event is fired?

im trying to make it find the direction of the tower since the event is being fired from the tower itself which is where “tower” part comes in and “towername” is unimportant for that code since it’s just the name of the tower

if its in a server script do:

tower.Sold:FireServer()

or if its in a local script do:

tower.Sold:FireAllClients -- All Clients or :FireClient -- One Client

Thats why it might not be working

its not remote event its a bindable event

1 Like

Maby try looking at this:
https://developer.roblox.com/en-us/api-reference/event/BindableEvent

1 Like

i don’t think its the issue with event since its same event i used to make the stats show on gui and it works perfectly fine there it just doesn’t want to get rid of the model itself i tried without firing event by just doing tower:Destroy() but it did not seem to work

I just changed the code into

script.Parent.MouseButton1Click:Connect(function()
local tower = script.Parent.Parent.Tower.Value
script.Parent.Parent.Parent.Enabled = false
tower:Destroy()

end)

since i just made it work like that previously and i found the issue i did not add value on the end so yeah.