I have a game in which players have a slime whose value is equal to their own name. And has another child value "isSlime" (The object itself is what the player named the slime.) Each object is in the workspace and I want to be able to delete this object with a gui in the players starte gui. I have the gui set up to function on click. And all I have to do is make the code.I just can't figure out how to make sure the script deletes an object with a child value of "isSlime" and a child value of the players specific name "name". Could someone help me figure out how to reference the specific slime and destroy; it on "button" click?
WHAT I'VE WRITTEN AND THINK MAY BE CORRECT SO FAR:
function onButtonClicked() local W = game.Workspace:GetChildren() local HasSlime = true for i = 1, #W do if W[i]:findFirstChild("IsSlime") ~= nil then
end end end
end
script.Parent.MouseButton1Click:connect(onButtonClicked)
You may find it easier to use an ObjectValue. Put it as a child of the Player and set its Value to be the Slime. Then, if you want to delete the slime, simply access the .Value and call :Destroy().
Another option is to name the slime player.Name .. "'s Slime"
. In that case, you could get it easily with slime = workspace:FindFirstChild(player.Name .. "'s Slime")
(and then, if it's not nil, :Destroy() it).