Hi i am trying to make a part follow a player when they click a button.
The part appears when the button is clicked but it doesnt follow the player. It just spawns next to them on the floor.
local MarketPlaceService = game:GetService("MarketplaceService")
local player = game:GetService("Players").LocalPlayer
local CatID = 87557759
local ItemFrame = script.Parent.Frame.ScrollingFrame
wait(player.Character:WaitForChild("HumanoidRootPart"))
local success, hasPass = pcall(function() -- Changing the pcall to the correct format
return MarketPlaceService:UserOwnsGamePassAsync(player.UserId, CatID)
end)
if success then -- Checking if successful
if hasPass then -- Checking if the player has the
local clone = script.Parent.Frame.ScrollingFrame.sample:Clone()
clone.ImageLabel.Image = "http://www.roblox.com/asset/?id="..10974691853
clone.Parent = script.Parent.Frame.ScrollingFrame
clone.Visible = true
clone.Equipped.Visible = false
local equip = clone.Equip
local clicks = 0
local pet = game.ReplicatedStorage.Pet2
equip.MouseButton1Click:Connect(function(equipped)
clone.Equipped.Visible = true
clicks += 1
local newpet = pet:clone()
local character = player.Character
if character ~= nil then
newpet:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
local modelsize = newpet.PrimaryPart.Size
local atachmentCharacter = Instance.new("Attachment")
atachmentCharacter.Visible = false
atachmentCharacter.Parent = character.HumanoidRootPart
atachmentCharacter.Position = Vector3.new(1, 1, 0) + modelsize
local alignposition = Instance.new("AlignPosition")
alignposition.MaxForce = 25000
alignposition.Attachment1 = atachmentCharacter
alignposition.Responsiveness = 25
alignposition.Parent = newpet
newpet.Parent = character
end
end)
Heres the script i am currently using.
The script did say this -
local attachmentpet = Instance.new("Attachment")
attachmentpet.Visible = false
attachmentpet.Parent = character
But it kept saying attachment must be parented to a basepart
Surely the attachment should be parented to the character to follow them?
Can anyone help to attach the part to the player?
Thankyou!