I want to make a button where a person touches it and they buy it. After buying it, the button disappears and a new model pops up. This script is not working for me.
script.Parent.Touched:Connect(function(hit)
if hit then
local player = game:GetService("Players")
if player then
local character = player:GetPlayerFromCharacter(hit.Parent)
if character then
if hit.leaderstats.cash.Value >= 0 then
local children = script.Parent.Parent:GetChildren()
children.Transparency = 1
children.CanCollide = false
opaque(game.Workspace.Dropper)
end
end
end
end
end)
I am also getting this in the output on line 7: [leaderstats is not a valid member of MeshPart]
You need to get the leaderstats using find first child I believe.
hit is the part that touches your button. leaderstats should be located within the Player object itself, so instead do:
character.leaderstats.cash.Value >= 0 then
The leaderstats is not in the character it is the the player (LocalPlayer)
That’s what I said. The OP defines character as local character = player:GetPlayerFromCharacter(hit.Parent) which makes it the Player object itself.
I just tried this and it did not work.
This did not work for me either.
but the leaderstats is NOT in the character
This is your problem. Your trying to change the properties of a table, I assume your trying to change all the parts in the table.
—Change this
local children = script.Parent.Parent:GetChildren()
children.Transparency = 1
children.CanCollide = false
—to
local children = script.Parent.Parent:GetChildren()
for i,v in pairs(children) do
v.Transparency = 1
v.CanCollide = false
end
—possible add If v:IsA(“Part”) then
— sorry mobile