Hello,
I’m making a game where the player can throw parts depending on their mouse position and if their holding one, the only issue is that I’m getting these errors.
I’m not sure how to fix them.
Errors
1
18:36:07.192 Attempt to connect failed: Passed value is not a function - Studio 18:36:07.197 Stack Begin - Studio 18:36:07.198 Script 'Workspace.NubblyFry.Brick.ThrowBrick', Line 17 - Studio - >ThrowBrick:17 18:36:07.198 Stack End - Studio2
18:36:07.310 CFrame is not a valid member of LocalScript >"Workspace.NubblyFry.HumanoidRootPart.Brick" - Client - Brick:13 18:36:07.310 Stack Begin - Studio 18:36:07.310 Script 'Workspace.NubblyFry.Brick', Line 13 - function >UpdatePartCFrame - Studio - Brick:13 18:36:07.310 Script 'Workspace.NubblyFry.Brick', Line 20 - Studio - Brick:20 18:36:07.310 Stack End - Studio3
18:36:14.266 Infinite yield possible on >'Workspace.NubblyFry.HumanoidRootPart:WaitForChild("HumanoidRootPart")' - >Studio 18:36:14.266 Stack Begin - Studio 18:36:14.266 Script 'Workspace.NubblyFry.Brick', Line 20 - Studio - Brick:20 18:36:14.266 Stack End - Studio
Scripts
Brick
local PartOffsetStuds = 2
local Part = nil
local DetectedEvent = script:WaitForChild("DetectedBrick")
local function UpdatePartCFrame(MovedPart, HumanoidRootPart)
-- Check if humanoid root part is not deleted/parented to nil
if HumanoidRootPart and HumanoidRootPart.Parent then Part.Parent = HumanoidRootPart
-- We want the part CFrame to be the same as HumanoidRootPart's, plus the x-# of studs in front
local PartCFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, -PartOffsetStuds)
-- Set the orientation and position at the same time with CFrame
MovedPart.CFrame = PartCFrame
else
warn("HumanoidRootPart does not exist! Cannot safely read CFrame.")
end
end
game:GetService("RunService").Heartbeat:Connect(function()
if Part ~= nil then UpdatePartCFrame(Part, script.Parent:WaitForChild("HumanoidRootPart")) end
if script.Parent:WaitForChild("Brick") then Part = script.Parent:WaitForChild("Brick") DetectedEvent:Fire(Part) else return end
end)
ThrowBrick
local UIS = game:GetService("UserInputService")
local brick = nil
function DetectedBrick(brickSent)
brick = brickSent
end
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and brick ~= nil then
local MousePos = game.Players.LocalPlayer:GetMouse().Hit.Position
brick:ApplyImpulse((MousePos - script.Parent:WaitForChild("HumanoidRootPart").Position))
end
end)
script.Parent:WaitForChild("DetectedBrick").Event:Connect(DetectedBrick)
---