Ok, so i made a button gui when you would press it a model would attach on the player now i want the script to delete the item when the button gui is pressed again I really don't know what to do.
01 | button = script.Parent.TextButton |
02 | local vc = game.ReplicatedStorage [ "Rig BP" ] |
03 | local plr = script.Parent.Parent.Parent |
04 | local char = plr.character or plr.CharacterAdded:Wait() |
05 |
06 | button.MouseButton 1 Down:Connect( function () |
07 |
08 | local Clonedvc = vc:Clone() |
09 | Clonedvc.Parent = char |
10 |
11 | Clonedvc:SetPrimaryPartCFrame(char:WaitForChild( "UpperTorso" ).CFrame) |
12 |
13 | Clonedvc:SetPrimaryPartCFrame(Clonedvc:GetPrimaryPartCFrame() * CFrame.new( 0 ,-. 84 ,. 02 ) * CFrame.Angles( 6.28 , 3.14 , 0 )) |
14 | local Weld = Instance.new( "WeldConstraint" ) |
15 | Weld.Part 0 = Clonedvc.Main |
16 | Weld.Part 1 = char:WaitForChild( "UpperTorso" ) |
17 | Weld.Parent = char:WaitForChild( "UpperTorso" ) |
18 | end ) |
See i think you just need to understand on how to go about it and then you can implement it on your script yourself.
for example: Consider this script:-
01 | local part = game.Workspace.Part |
02 | local Detec = part.ClickDetector |
03 | local ch = game.Workspace.Change |
04 | local attached = true |
05 |
06 | Detec.MouseClick:Connect( function () |
07 | if attached = = true then |
08 | attached = false |
09 | ch.Parent = game.ReplicatedStorage |
10 |
11 | elseif attached = = false then |
12 | attached = true |
13 | ch.Parent = game.Workspace |
14 | end |
15 | end ) |
here we are making a variable which turns to false when the thing is attached (just consider it for your understanding as attached however its not in my script) when i click the button and also turns true if it was false.
Hope this might help you!!