Attempt to call a userdata value, i dont know what this means, im on a script, not a local script, here is my code
script.Parent.MouseButton1Click:Connect(function() local toolname = script.Parent.Parent.Itemname.Text local cost = script.Parent.Parent.Price.TextLabel.Text local tool = game.ReplicatedStorage(toolname) local money = script.Parent.Parent.Parent.Parent.Parent.Parent if money <= tonumber(cost) then money = money - cost local tool = tool:Clone() tool.Parent = game.Players.LocalPlayer.Backpack end end)
Hello.
Instead of using (toolname)
, you must use [toolname]
, as in Roblox Lua, that's how you index instances despite the dot operator.
Also, game.Players.LocalPlayer
won't work in a normal script, so you have to use a RemoteEvent
, or get the player by using script.Parent.Parent.Parent.Parent
.
script.Parent.MouseButton1Click:Connect(function() local toolname = script.Parent.Parent.Itemname.Text local cost = script.Parent.Parent.Price.TextLabel.Text local tool = game.ReplicatedStorage[toolname] local money = script.Parent.Parent.Parent.Parent.Parent.Parent if money >= tonumber(cost) then money = money - cost local tool = tool:Clone() tool.Parent = game.Players.LocalPlayer.Backpack end end)
Urm I don't thin you needed tonumber so try this
script.Parent.MouseButton1Click:Connect(function() local toolname = script.Parent.Parent.Itemname.Text local cost = script.Parent.Parent.Price.TextLabel.Text local tool = game.ReplicatedStorage(toolname) local money = script.Parent.Parent.Parent.Parent.Parent.Parent if money <= cost then money = money - cost local tool = tool:Clone() tool.Parent = game.Players.LocalPlayer.Backpack end end)