Ok this has to be an easy fix and I just do not know why it is not working. If anyone can help me and tell me why I am being so dumb right now I would love it.
--Give the player ingredients on click
local RS = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local backpack = player.Backpack
local ingredientsFolder = game.Workspace:WaitForChild("IngredientsGivers")
local potionModelFolder = RS:WaitForChild("PotionModels")
print("This works")
for _, ingredient in pairs(ingredientsFolder:GetChildren()) do
local prompt = ingredient:WaitForChild("ProximityPrompt")
prompt.Triggered:Connect(function()
local clone = potionModelFolder:FindFirstChild(ingredient.Name):Clone()
clone.Parent = backpack
print("This works")
end)
end
I don’t know what is wrong here. I am having a brain fart
That did not work, I tried changing that and it did not work so then I tried this and it still does not work.
--Give the player ingredients on click
local RS = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local backpack = player:WaitForChild("Backpack")
local ingredientsFolder = game.Workspace:WaitForChild("IngredientsGivers")
local potionModelFolder = RS:WaitForChild("PotionModels")
print("This works")
for _, ingredient in pairs(ingredientsFolder:GetChildren()) do
local prompt = ingredient:WaitForChild("ProximityPrompt")
prompt.Triggered:Connect(function()
print("This works")
local partToClone = potionModelFolder:WaitForChild(ingredient.Name)
local clone = partToClone:Clone()
clone.Parent = backpack
end)
end
My script is in StarterPlayerScripts if maybe that is what is wrong?
Just tested this myself, seems like it is a Client issue, but when ported to a Server script, it works fine.
Here is the version that you should put into a script in ServerScriptService, doing this on the server is more reliable and the Tool will replicate for other players.
--Give the player ingredients on click
local RS = game:GetService("ReplicatedStorage")
local ingredientsFolder = game.Workspace:FindFirstChild("IngredientsGivers")
local potionModelFolder = RS:FindFirstChild("PotionModels")
for _, ingredient in pairs(ingredientsFolder:GetChildren()) do
local prompt = ingredient:FindFirstChild("ProximityPrompt")
prompt.Triggered:Connect(function(Player)
local backpack = Player:FindFirstChildWhichIsA("Backpack")
if not backpack then return end
local partToClone = potionModelFolder:FindFirstChild(ingredient.Name)
if not partToClone then return end
local clone = partToClone:Clone()
clone.Parent = backpack
end)
end
Okay yeah, so I was able to get it also on the client it seems like I was trying to do everything before it all loaded in so I adjusted my script to this:
--Give the player ingredients on click
local RS = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local ingredientsFolder = game.Workspace:WaitForChild("IngredientsGivers")
if #ingredientsFolder:GetChildren() == 0 then
ingredientsFolder.ChildAdded:Wait()
end
local potionModelFolder = RS:WaitForChild("PotionModels")
print("This works")
for _, ingredient in pairs(ingredientsFolder:GetChildren()) do
local prompt = ingredient:WaitForChild("ProximityPrompt")
prompt.Triggered:Connect(function()
print("This works")
local partToClone = potionModelFolder:WaitForChild(ingredient.Name)
local clone = partToClone:Clone()
clone.Parent = player.Backpack
end)
end
And it worked. Which do you think would be better? Would the server option be better even if this works or is keeping track of tools on the client better?
Actually I just tested it and this is perfect, thank you! I realized as you said that others can not see the tool that I am holding if I do it all on the client and I do not want that. Thank you so much for your help!!!