I am making an inventory script for a basketball game. The inventory script changes the ball’s look. The different models are stored in another model which I will fix later.
The issue is that right after the change, the tool disappears. Video linked below:
Code
The code is a local script inside of the button itself that changes the ball’s appearance.
local player = game.Players.LocalPlayer
local ball = player.Backpack:WaitForChild("Basketball", math.huge)
local style = ball:WaitForChild("Handle")
script.Parent.MouseButton1Click:Connect(function()
if ball then
player.Character.Humanoid:UnequipTools()
style:Destroy()
local newBall = game.Workspace.Models.FF:Clone()
newBall.Parent = ball
newBall.Name = "Handle"
end
end)
I dont recommend destroying handles as it causes issues for the tool, instead, change the handles transparency to 1 and clone it, set the clones transparency to 0 and change its position to whatever the handles position is, then you can weld them.
Preferably, if you’re not changing the physical brick of the ball, just how it looks, you should store the values in a table and retrieve them whenever you need to. This way, the tool never has to get destroyed:
local player = game.Players.LocalPlayer
local ball = player.Backpack:WaitForChild("Basketball", math.huge)
local style = ball:WaitForChild("Handle")
script.Parent.MouseButton1Click:Connect(function()
if ball then
local reference = game.Workspace.Models.FF:Clone()
style.BrickColor = reference.BrickColor
style.Material = reference.Material
... (and so on)
end
end)