#Function not working when proximityprompt triggered!

1 messages · Page 1 of 1 (latest)

violet nacelle
#

it is a give item script. when i go to the dev console and direct enter the global function and player to myself, it works but in a script when a proximityprompt triggered, it wont give me the item and returns no error in the console
pls help

#
local ItemService = require(game.ServerScriptService:WaitForChild("ItemService"))

local part = script.Parent
local prompt = part:WaitForChild("pPromptRock")

prompt.Triggered:Connect(function(player)
    local success, message = ItemService.GivePlayerItem(player, "Rock")
    if not success then
        warn("[RockGiver] Failed to give Rock to " .. player.Name .. " - Reason: " .. (message or "Unknown Error"))
    else
        print("[RockGiver] Rock successfully given to " .. player.Name)
    end
end)```
#
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ItemService = {}

print("Loaded ItemService Module! 100% Initialized!")

function ItemService.GivePlayerItem(player, itemName)
    if not player or not player:IsA("Player") then
        warn("[ItemService ERROR] Invalid player provided!")
        return false, "Invalid player"
    end

    local itemTemplate = ReplicatedStorage:FindFirstChild("Models")
    if not itemTemplate then
        warn("[ItemService ERROR] Models folder not found in ReplicatedStorage! DEVS_FIX_NOW_0")
        return false, "Models folder missing"
    end

    local item = itemTemplate:FindFirstChild(itemName)
    if not item then
        warn("[ItemService ERROR] Item: "..itemName.." not found in Models folder! DEVS_FIX_NOW_1")
        return false, "Item not found"
    end

    if not item:IsA("Tool") then
        warn("[ItemService ERROR] "..itemName.." is not a Tool! DEVS_FIX_NOW_2")
        return false, "Item is not a Tool"
    end

    local clonedItem = item:Clone()
    local success, err = pcall(function()
        local backpack = player:FindFirstChild("Backpack") or player:WaitForChild("Backpack")
        clonedItem.Parent = backpack
    end)

    return true
end

return ItemService```
sharp basalt
violet nacelle
#

and also btw why does it say infiniteyield possible, it is literlaly roblox studio

violet nacelle
#

it existed

forest pastureBOT
#

studio** You are now Level 2! **studio

violet nacelle
violet nacelle
bold locust
#

If so, then that's most likely the root cause of all these issues

sharp basalt
sharp basalt
#

and yeah it usually means a typo or wrong folder, or replication issue if it's on client

bold locust
sharp basalt
#

or in those fun times when you forget to create it entirely hehe

bold locust
#

Sadly roblox doesn't typecast the same as other languages, as some other ones would just instantly complain about a wrong type

sharp basalt
bold locust
sharp basalt
#

If a call to this method exceeds 5 seconds without returning, and no timeOut parameter has been specified, a warning will be printed to the output that the thread may yield indefinitely.

sharp basalt
sharp basalt
loud forge
sharp basalt
bold locust
loud forge
bold locust
#

Unless that's your definition of a "silent error"

loud forge
#

Oh you helpong sm1?

#

ill leave you be then

#

👋

sharp basalt
#

very bad idea ;p

bold locust
#

That just sounds like an awful idea

#

Let's be frank, if any script has to wait for an object for over the given 5 seconds then I would be more concerned about performance than actual errors

sharp basalt
#

excessively long timeouts are just as bad, so there isn't much reason to use the timeout, maybe 30sec tops, i guess it can be used to save a loop and an instance.childadded:wait() in some situations

#

roblox's plant project uses safewaitforchild which does that thonkoof

bold locust
#

(unless it's designed in such a way, which to me sounds like an awful code design. Then you're best off using a callback or something similar)

sharp basalt
#

i guess it has its uses, kinda rare tho

violet nacelle
#

so....