Everything is "index nil"

For some reason my one local script is saying everything is nil. The script looks fine from my view so I’m not sure if there’s something I’m doing wrong.
Script:

local Events = game:GetService('ReplicatedStorage').Dealership_Events
local function ResizeBar(percent, Inside)
	Inside:TweenSize(UDim2.new(percent/100, 0, 1 ,0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 1, true)
end

script.Parent.MouseButton1Click:Connect(function()
	Events.SpawnVehicle:FireServer(script.Parent.Parent.Name, script.Parent.Parent.Parent.Parent.WhichDealership.Value)
end)

Error:

attempt to index nil with 'MouseButton1Click'

Please can anyone help as I’m very confused with what’s happening.

1 Like

Is the script’s Parent definitely a TextButton?

If so, it might just be that the client hasn’t had time to register it.

You could try adding something above that line, maybe something like:

repeat wait(1) until script.Parent ~= nil

I hope this helps.

3 Likes

Hello!

Alongside what @12345koip mentioned, check if the button has the Active property enabled.

If not, enable it. It could fix your issue as it then should be able to sink in input. (It is defaultly enabled)

2 Likes

I added this and it fixed the issue, thank you as well as @nyxon.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.