--Big Script Ahead; Okay so i am trying to create an extremely but effective pickup system with just raycasting and welding a part to a part (the game is first person keep that in mind), And i have all of that done but its going completely out of wack, Because after i drop an item i can still pick up one even if im not looking anywhere remotely close to it (i have an Apple and a Banana it is picking up the first one that it can find which would be Apple), And if i keep pressing e enough multiple things have chances of happening: it gets parented to nil, It just flings into outerspace, It Immediately gets deleted, or It causes the player to freak out (only had this 1 in an older version of the script). any help here that actually helps is appreciated i have put several check into the script that all failed and then the current checks are just being bypassed and the script executes anyway
LocalScript:
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Look = script.Parent.LookGui
local Debounce = false
local CarryingItem = false
local PickupEvent = game.ReplicatedStorage.PickUp
local Holder = Instance.new("Part")
local Part = nil
Holder.Size = Vector3.new(0.5, 0.5, 0.5)
Holder.Anchored = false
Holder.CanCollide = false
Holder.Parent = workspace
Holder.Transparency = 1
RunService.RenderStepped:Connect(function(step)
if CarryingItem == true then
Holder.CFrame = Head.CFrame + Head.CFrame.LookVector.Unit * 7
Part.CFrame = Holder.CFrame
end
local viewportPoint = Camera.ViewportSize / 2
local unitRay = Camera:ViewportPointToRay(viewportPoint.X, viewportPoint.Y, 0)
local ray = Ray.new(unitRay.Origin, unitRay.Direction * 7)
local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {Character, Holder}, true, true)
if part then
if part:FindFirstChild("Interactable") then
Look.Enabled = true
Holder.Position = position
UIS.InputBegan:Connect(function(input, recieved)
if UIS:GetFocusedTextBox() == nil then
if input.KeyCode == Enum.KeyCode.E and Debounce == false or input.KeyCode == Enum.KeyCode.ButtonY and Debounce == false then
Debounce = true
CarryingItem = not CarryingItem
if CarryingItem == false then
Holder:FindFirstChild("HolderWeld"):Destroy()
PickupEvent:FireServer(Part, "Drop")
Part = nil
local PlayerWeld = Instance.new("WeldConstraint")
PlayerWeld.Name = "PlayerWeld"
PlayerWeld.Parent = Holder
PlayerWeld.Part0 = Holder
PlayerWeld.Part1 = Head
Holder.Transparency = 1
else
if part:FindFirstChild("Interactable") then
Part = part
PickupEvent:FireServer(Part, "PickUp")
if Holder:FindFirstChild("PlayerWeld") then
Holder:FindFirstChild("PlayerWeld"):Destroy()
end
local Weld = Instance.new("WeldConstraint")
Weld.Parent = Holder
Weld.Part0 = Holder
Weld.Part1 = part
Weld.Name = "HolderWeld"
Holder.Transparency = 0
end
end
wait(.5)
Debounce = false
end
end
end)
end
else
Look.Enabled = false
end
end)
Script:
local Event = game.ReplicatedStorage.PickUp
Event.OnServerEvent:Connect(function(Player, Item, Status)
if Status == "PickUp" then
print("Picked up " .. Item:GetFullName())
Item.Anchored = false
Item:SetNetworkOwner(Player)
end
if Status == "Drop" then
print("Dropped ".. Item:GetFullName())
Item:SetNetworkOwner(nil)
end
end)
do keep in mind this game is going to be a single player game so security is not my biggest priority, I don't really want as many checks as LT2, they can enjoy the game at their will
