Player = script.Parent.Parent Character = Player.Character game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) if msg == "Equip" then print("DIE") Part = Instance.new("Part") Part.Size = Vector3.new(5,5,5) Part.BrickColor = BrickColor.new("Really red") Weld = Instance.new("Weld",Character) Weld.Part0 = Weld.Parent["Right Arm"] Weld.Part1 = Part Weld.C1 = CFrame.Angles(0, 0, 0) *CFrame.new(0, 0, 5) end end) end)
script.Parent.Parent gets me to DataModel suddently?
How do I find a players character?
First of all, make this a LocalScript if it is being used inside the player. Secondly, you do not need to write a "PlayerAdded" event to get the player's chat. Just do:
local Player = game.Players.LocalPlayer repeat wait() until Player.Character --Wait for the character to spawn in local Character = Player.Character Player.Chatted:connect(function(Msg) --Stuff end)
You have to make sure the character has loaded first, and update the character whenever it respawns. Also, parent the weld to the brick, because welds should always be parented to their C0 values
Make sure this script is in ServerScriptService
game.Players.PlayerAdded:connect(function(player) repeat wait() until player.Character --wait for the character to load local character = player.Character --define character game.Players.CharacterAdded:connect(function(c) character = c --update the character whenever a new one respawns end) player.Chatted:connect(function(msg) local arm = character:FindFirstChild("Right Arm") --make a variable for the arm if not arm then return end --terminate code if there is no arm if msg:lower() == "equip" then print("DIE") Part = Instance.new("Part") Part.Size = Vector3.new(5,5,5) Part.BrickColor = BrickColor.new("Really red") Weld = Instance.new("Weld",arm) Weld.Part0 = arm Weld.Part1 = Part Weld.C1 = CFrame.Angles(0, 0, 0) *CFrame.new(0, 0, 5) end end) end)