#Part linking error

1 messages · Page 1 of 1 (latest)

thorn kite
#

20:22:47.176 collectiblesFolder is not a valid member of Workspace "Workspace" - Server - CollectablesHandler:27

So pretty much its saying that this folder is not in Workspace, the only thing is that the folder is created locally for the player and only that player not globally.

I'm trying to make a collect system where parts spawn locally and now i need to do the logic to ensure that the parts are legit and should be rewarded then reward them with a script in ServerScript.

The script is shown below

CollectEvent.OnServerEvent:Connect(function(player, part)
    print("Collect Event Recieved")
    if not part then warn("Error-1") return end
    if not part:IsDescendantOf(workspace.collectiblesFolder) then warn("Error0") return end

    local char = player.Character
    if not char then warn("Error1") return end
    local hrp = char:FindFirstChild("HumanoidRootPart")
    if not hrp then warn("Error2") return end

    local radius = player:GetAttribute("Radius") or 0
    if (part.Position - hrp.Position).Magnitude <= radius then

        local reward = part:GetAttribute("Value") or 1
        print(player.Name .. " collected a part worth " .. reward)

        local state = player:GetAttribute("Money")
        player:SetAttribute("Money", state + reward)

        part:Destroy()
    else
        warn("Error3")
    end
end)```