I'm new to scripting and still learning.
Okay, so when a player joins I want a Katana to be part of the player model.
I made this script for that to happen
sword = game.Lighting.Katana
weld = game.Lighting.Weld
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
local NewSword = sword:Clone()
NewSword.Parent = character
local rotation = Vector3.new(0, 0, 0)
NewSword.CFrame = character:WaitForChild("Left Leg").CFrame + Vector3.new(0.55, 0.4, 0) - Vector3.new(0, 0, 1.7)
NewSword.Rotation = rotation + Vector3.new(170, 0, -90)
local ImWeld = weld:Clone()
ImWeld.Parent = character
end)
end)
The problem is that player walking animation doesn't play/work.
GIF: https://gyazo.com/cd306ac2e402a5738e9cb678e2e6b535
I don't know much about welding or keeping parts together so I'm using a free model weld script to hold the player and the sword together, but I'm pretty sure that is what is stopping animation from playing. I also don't know much about cframe either.
Code of free model weld script
local all,last = {}
function scan(p)
for _,v in pairs(p:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Wheel" then
if (last) then
local w = Instance.new("Weld")
w.Part0,w.Part1 = last,v
w.C0 = v.CFrame:toObjectSpace(last.CFrame):inverse()
w.Parent = last
end
table.insert(all,v)
last = v
end
scan(v)
end
end
scan(script.Parent)
for _,v in pairs(all) do v.Anchored = false end
And I'm wondering if there is a better way to keep a object/part on on the player

3 comments
I understand some parts of the weld scripts, but other parts I don't get it. Like I have no idea what " for _,v in pairs" means
Do you know any tutorials on roblox wiki, or youtube videos that can teach me about it?
This is the reference for Lua for loops: http://www.lua.org/pil/7.3.html - pairs is a function which returns an iterator which allows you to loop through each key=value pair in a table. Tricky, huh?