Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how would i add a bool value checking to see if its on the player?

Asked by 5 years ago

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.

01button = script.Parent.TextButton
02local vc = game.ReplicatedStorage["Rig BP"]
03local plr = script.Parent.Parent.Parent
04local char = plr.character or plr.CharacterAdded:Wait()
05 
06button.MouseButton1Down: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.Part0 = Clonedvc.Main
16        Weld.Part1 = char:WaitForChild("UpperTorso")
17        Weld.Parent = char:WaitForChild("UpperTorso")
18    end)
0
and like if its on the player = true then :destroy() Fxding_cam 60 — 5y
0
so basically you are saying that once when you have clicked you want that attached and second time when clicked you want it to destroy? hallmk7 50 — 5y
0
yes Fxding_cam 60 — 5y

1 answer

Log in to vote
1
Answered by
hallmk7 50
5 years ago

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:-

01local part = game.Workspace.Part
02local Detec = part.ClickDetector
03local ch = game.Workspace.Change
04local attached = true
05 
06Detec.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
15end)

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!!

0
the change going to the replicated storage part worked Fxding_cam 60 — 5y
0
but how do i make it come back to workspace if i press it again? would i have to loop the script for inv. Fxding_cam 60 — 5y
0
inf* Fxding_cam 60 — 5y
0
wait nvm i missed some parts sorry Fxding_cam 60 — 5y
Ad

Answer this question