How do I make it if I touched a textbutton the material of the part will change locally?

How do I make it if I touched a textbutton the material of the part will change locally?

So I did this and put this in my screengui placed in startergui

local workspace = game:GetService(“Workspace”)
local UserInputService = game:GetService(“UserInputService”)
local MaterialService = game:GetService(“MaterialService”)

local g1p = game.Workspace:FindFirstChild(“Test2”)

detector.MouseButton1Click:Connect(function()
local textButtonSwitch = false
g1p.Material = Enum.Material.Plastic
local textButtonSwitch = true
end)

And when I click on the textbutton it says this error Players.angelafaye0223.PlayerGui.Inv.LocalScript:16: attempt to index nil with ‘Material’
and it doesnt change the material. Any solutions?

1 Like

Make it :WaitForChild() maybe?

2 Likes

Have you made sure Test2 exists? Try using WaitForChild instead of FindFirstChild

3 Likes

Does the part actually exist? Maybe you could change FindFirstChild to WaitForChild

2 Likes

It does exist in workspace. Sure Ill try that.

It worked thanks for the help everyone.

2 Likes

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