Hello!
I’ve been working on a game, and I have created a simple pickup system. It is shown below:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage.Remotes
local Message = Remotes.Message
local Prompt = script.Parent
Prompt.Triggered:Connect(function(Player)
local Distance = Player:DistanceFromCharacter(Prompt.Parent.Position)
if Distance > 6 then
return
end
if Player.Character.Humanoid.Health <= 0 then return end
local Origin = Player.Character.PrimaryPart.Position
local Direction = (Prompt.Parent.Position - Origin).Unit * 4500
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {Player.Character}
Params.FilterType = Enum.RaycastFilterType.Exclude
local Raycast = workspace:Raycast(Origin, Direction, Params)
if not Raycast then return end
if not Raycast.Instance:FindFirstAncestorOfClass("Model") then return end
if Raycast.Instance:FindFirstAncestorOfClass("Model") ~= Prompt.Parent.Parent then return end
local Tool = Prompt.Parent.Parent.Tool.Value:Clone()
Tool.Parent = ReplicatedStorage
Tool.Parent = Player.Backpack
Prompt.Parent.Parent:Destroy()
end)
(the code is a bit messy, but thats besides the point.)
The code works perfectly fine, until… the player dies.
If the player has died ONCE in the entire server, when they attempt to pickup the tool, the tool does NOT get parented to their backpack. Instead, it somehow ends up in workspace, and falls through the map. This is shown below:
Is there any idea on why this is occurring? It’s been frustrating me for hours now. I haven’t seen another post like this.
Ive noticed, regardless of what I do, the tool will always end up in workspace. Even if I forcefully make the humanoid equip the tool- the tool ends up in workspace.