So i made an armor suit, i tested it by spawning my character in and creating the constraint manually.
afterwards, i decided to write a script that would make the player equip the armor upon clicking it.
Though it seems i’m doing something wrong, as nothing is happening.
Here’s the code:
local players = game:GetService("Players")
local player = players.LocalPlayer.Character:FindFirstChildWhichIsA("Humanoid")
script.Parent.ClickDetector.MouseClick:Connect(function()
if script.Parent.ClickDetector.MouseClick then
local ArmorClone = script.Parent.Parent:Clone()
local Joint = Instance.new("RigidConstraint")
Joint.Parent = ArmorClone
Joint.Attachment0 = player.Parent:FindFirstChild("RootAttachment")
Joint.Attachment1 = ArmorClone
end
end)
i assume it’s wrong in terms of linking it all to actual player model, but i don’t understand what am i doing wrong in particular.
local click = script.Parent
local part = click.Parent
local model = part.Parent
click.MouseClick:Connect(function(player)
local character = player.Character
local hrp = character:WaitForChild("HumanoidRootPart")
local modelClone = model:Clone()
local attachment1 = Instance.new("Attachment")
attachment1.Parent = hrp
local attachment2 = Instance.new("Attachment")
attachment2.Parent = modelClone.Part
local joint = Instance.new("RigidConstraint")
joint.Attachment0 = attachment1
joint.Attachment1 = attachment2
joint.Parent = character
modelClone.Parent = workspace
end)
Server script.
“game.Players.LocalPlayer” isn’t defined in server scripts.
I looked further into the issue, Rigid constraints work fine, but cloning process is botched.
Edit: I made a new line of code right bellow line that does the actual cloning:
modelClone.Parent = character
And that seemed to fix it, while character wears it wrong, i’ll figure out that issue myself.
local click = script.Parent
local part = click.Parent
local model = part.Parent
click.MouseClick:Connect(function(player)
local character = player.Character
local hrp = character:WaitForChild("HumanoidRootPart")
local modelClone = model:Clone()
local attachment1 = Instance.new("Attachment")
attachment1.Parent = hrp
local attachment2 = Instance.new("Attachment")
attachment2.Parent = modelClone.Part
local joint = Instance.new("RigidConstraint")
joint.Attachment0 = attachment1
joint.Attachment1 = attachment2
joint.Parent = character
modelClone.Parent = workspace
end)