Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Psudar
- 7/17/2019
- How to use:
- --Make sure the script is parented to the hat model containing all the parts and such
- --Make sure theres a click detector also parented directly to the hat model
- --Make sure theres a psuedo head inside of the hat model, this is for positioning the hat however you may want.
- Cheers.
- ]]
- local hatModel = script.Parent --intitial model containing parts
- local clickDetector = hatModel:WaitForChild("ClickDetector") --clickdetector is for detecting clicks hehe
- local function weldParts(part0, part1) -- welds the 2 parts based on their position
- local newWeld = Instance.new("Weld")
- newWeld.Part0 = part0
- newWeld.Part1 = part1
- newWeld.C0 = CFrame.new()
- newWeld.C1 = part1.CFrame:toObjectSpace(part0.CFrame)
- newWeld.Parent = part0
- end
- local function onClicked(player) --player who clicked will be returned when called from event
- if not player.Character:FindFirstChild(hatModel.Name) then
- if player.Character:FindFirstChild("Head") then --check for a head
- local playerHead = player.Character:FindFirstChild("Head") --save their head
- local newModel = hatModel:Clone() --clone the intitial model (the one this script is parented to)
- local newHead = newModel:WaitForChild("Head")--get the head from the new model, will be used for positioning later
- newModel.PrimaryPart = newHead --set primary part to the head
- newModel:SetPrimaryPartCFrame(playerHead.CFrame) --set the primary parts cframe to the player's head
- newModel:SetPrimaryPartCFrame(playerHead.CFrame) -- puts the head into the head
- newModel.PrimaryPart:Destroy() --destroy the new head
- for _, part in pairs (newModel:GetDescendants()) do --cycle through model descendants (everything inside of it)
- if part:IsA("BasePart") then --check for if its a part
- weldParts(playerHead, part) --call weld function on every part, welding it to the player's
- part.CanCollide = false
- part.Anchored = false
- end
- end
- newModel.Parent = player.Character --set model parent to player's character
- end
- else
- player.Character:FindFirstChild(hatModel.Name):Destroy() --removes hat
- end
- end
- clickDetector.MouseClick:Connect(onClicked)
- ------------------//END SCRIPT\\---------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement