Touched Event Error on ButtonPart

I’m making a tycoon game and I’m currently scripting the button function for my game.

The code looks like this:


I keep receiving this error though.

This is my button
image

I’m confused as to why the touched wont work and assumes its not a valid member? Please help!

The ButtonPart is a model so that’s why, you have to change
v.ButtonPart.Touched to the actual part inside it like
v.ButtonPart.Button.Touched

I’ll check this out and lets hope it works!


Now receiving this error.

do you mind sharing the screenshot of explorer showing inside that ButtonPart Model?

image

v.ButtonPart["Meshes/bUTTONS_Cylinder"].Touched
if that doesn’t work try
v.ButtonPart["Meshes/bUTTONS_Cylinder.001"].Touched

(you can change the name of that two part inside it to make it easier to use it with script)

Could you send the full script so we’re getting less confused and more simpler to fix?

Also, please don’t put it as an image, if you see “</>”, click on it, it’ll do:

--aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Just to remind you, that this is an example, don’t copy the script.

To make it EVEN MORE SIMPLER, use a LocalFile.

The script for the buttons is

for i, v in pairs(Buttons:GetChildren()) do
	local NewItem = BoughtItems:FindFirstChild(v.Item.Value)
	if NewItem ~= nil then
		Items[NewItem.Name] = NewItem:Clone()
		NewItem:Destroy()
	else
		v.ButtonPart.Transparency = 1
		v.ButtonPart.CanCollide = false
		v.ButtonPart.BillboardGui.Frame.Visible = false
	end

	if v:FindFirstChild("Dependency") then
		coroutine.resume(coroutine.create(function()
			v.ButtonPart.Transparency = 1
			v.ButtonPart.CanCollide = false
			v.ButtonPart.BillboardGui.Frame.Visible = false
			if BoughtItems:WaitForChild(v.Dependency.Value, 1000000) then
				v.ButtonPart.Transparency = 0
				v.ButtonPart.CanCollide = true
				v.ButtonPart.BillboardGui.Frame.Visible = true
			end
		end))
	end

	v.ButtonPart["Top"].Touched:Connect(function(Hit)
		if Hit.Parent:FindFirstChild("Humanoid") then
			local player = game.Players:GetPlayerFromCharacter(Hit.Parent)
			if Values.OwnerValue.Value == player then
				if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
					if player:WaitForChild("leaderstats").Cash.Value >= v.Price.Value then
						player.leaderstats.Cash.Value -= v.Price.Value
						Items[v.Item.Value].Parent = BoughtItems
						v:Destroy()
					end
				end
			end
		end
	end)
end

image
I renamed the button meshes to top and bottom.

did it solve the problem? if so, you can mark as solution to help others too

It caused another error within the code,

okay so change this too
if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency == 0 then
to
if v.ButtonPart.Top.CanCollide == true and v.ButtonPart.Top.Transparency == 0 then

1 Like

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