#Function not working when proximityprompt triggered!
1 messages · Page 1 of 1 (latest)
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```
maybe the prompt doesnt exist or has wrong name or something, that waitforchild could be infinite yield.
wdym, it works and gives me the item when i enter the function in the F9 serverside console but the proximityprompt just doesnt return any error or what
and also btw why does it say infiniteyield possible, it is literlaly roblox studio
i already asplained that
👍
it existed
** You are now Level 2! **
*exist
pls help bro, im a beginner and it just does not function, there are no logs in the F9 console
I recall roblox only giving that error after a few seconds of it not being able to find the right instance, a few seconds for most games would mean a typo (or replication issue). Is that still the case?
If so, then that's most likely the root cause of all these issues
use the studio output window not the f9 console.
it's a warning and it fires after 5 seconds, you can override it to make it longer or turn it off but that's usually a bad idea because it results in silent errors.
and yeah it usually means a typo or wrong folder, or replication issue if it's on client
It should then just return nil, which will give you some type error later down the stack
or in those fun times when you forget to create it entirely 
Sadly roblox doesn't typecast the same as other languages, as some other ones would just instantly complain about a wrong type
waitforchild never returns nil. it throws the warning and continues to yield, it does not resume execution.
Isn't that what the second param was for?
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.
this is correct, adding the second parameter will make it return nil instead of infinite yield
If the timeOut parameter is specified, this method will time out after the specified number of seconds and return nil.
omg pyro?
hiiiii
hi 👋
whatca been up to
roblox
So then the overwrite will not result in silent errors, just in type errors instead
me 2, ive gotten a lot better at scripting.
Unless that's your definition of a "silent error"
i was mostly thinking of math.huge
very bad idea ;p
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
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 
(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)
i guess it has its uses, kinda rare tho
so....