I am trying to make a ROBLOX players arm follow the mouses position, I have not yet found any code or videos relating to this. Anyone here got a solution?
NOTE: IF THIS IS THE WRONG CATAGORY PLEASE TELL ME AS FAST AS POSSIBLE
I am trying to make a ROBLOX players arm follow the mouses position, I have not yet found any code or videos relating to this. Anyone here got a solution?
NOTE: IF THIS IS THE WRONG CATAGORY PLEASE TELL ME AS FAST AS POSSIBLE
Have you tried this solution?
that works whenever, but i want it to only work when you equip a tool and it deactivates when u unequip
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local armOffset = char.UpperTorso.CFrame:Inverse() * char.RightUpperArm.CFrame
local armWeld = Instance.new("Weld")
armWeld.Part0 = char.UpperTorso
armWeld.Part1 = char.RightUpperArm
armWeld.Parent = char
script.Parent.Parent.Equipped:Connect(function()
mouse.Icon = "rbxassetid://316279304"
RunService.Heartbeat:Connect(function()
local cframe = CFrame.new(char.UpperTorso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0)
armWeld.C0 = armOffset * char.UpperTorso.CFrame:toObjectSpace(cframe)
end)
end)
script.Parent.Parent.Unequipped:Connect(function()
mouse.Icon = ""
end)
this is what I have so far but its saying char is nil
Make sure to use a local script, .LocalPlayer only works in local scripts.
here is a modified version that also handles the connection on unequip
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local plr = Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local mouse = plr:GetMouse()
local armOffset = char.UpperTorso.CFrame:Inverse() * char.RightUpperArm.CFrame
local armWeld = Instance.new("Weld")
armWeld.Part0 = char.UpperTorso
armWeld.Part1 = char.RightUpperArm
armWeld.Parent = char
local armPointConnection
local tool = script:FindFirstAncestorWhichIsA("Tool")
tool.Equipped:Connect(function()
mouse.Icon = "rbxassetid://316279304"
armPointConnection = RunService.Heartbeat:Connect(function()
local cframe = CFrame.new(char.UpperTorso.Position, mouse.Hit.Position) * CFrame.Angles(math.pi/2, 0, 0)
armWeld.C0 = armOffset * char.UpperTorso.CFrame:toObjectSpace(cframe)
end)
end)
tool.Unequipped:Connect(function()
mouse.Icon = ""
if armPointConnection then
armPointConnection:Disconnect()
end
end)
" 12:11:30.683 UpperTorso is not a valid member of Model “Workspace.GamingExpert0312” - Client - ClientMain:8"
this is the error i get repeatedly
the character is r15, not r6 btw
This means the characters upper torso model hasn’t loaded into the game yet, use a :WaitForChild(“UpperTorso”) to wait for it to load into the game.
ah makes sense, why didnt i think of that. ill let you know if it works
it is just saying infinite yield on all :waitforchild() statements
write wait(1)
on line 1. so the player will load the first second and then the script will start running