I made a quick Cup Giver script for a cafe game that I’m working on, but the cup giver isn’t working due to this bug. You can see the script below. The part that has puzzled me the most is that I’ve used this script previously in previous games, and even threw it into a new place and tested it out, and sure enough; it works. It’s only the game I’m currently working on where this error has occurred.
local GivePart = script.Parent.GivePart
local ClickDetector = GivePart.ClickDetector
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cup = ReplicatedStorage.Cup
ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
local CupClone = Cup:Clone()
CupClone.Parent = PlayerWhoClicked.Backpack
end)
Try changing local Cup = ReplicatedStorage.Cup to local Cup = ReplicatedStorage:WaitForChild("Cup") as the script might be creating the reference before the instance actually arrives in ReplicatedStorage.
Ok, I did a quick recreation with an empty tool named “Cup” in ReplicatedStorage, using your code, and it worked. Is something deleting Cup from ReplicatedStorage after the server is started?
Did you check that the archivable property on your cup is true? Clone will return nil if that’s false. If the code was having issues finding the cup I believe it would error on the clone instead of when you set the parent.
local GivePart = script.Parent.GivePart
local ClickDetector = GivePart.ClickDetector
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cup = ReplicatedStorage.Cup
ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
local CupClone = Cup:Clone()
print(Cup:GetFullName(), CupClone:GetFullName())
CupClone.Parent = PlayerWhoClicked.Backpack
end)
Oops. I should have put those in separate print statements.
Do this instead
local GivePart = script.Parent.GivePart
local ClickDetector = GivePart.ClickDetector
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cup = ReplicatedStorage.Cup
ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
local CupClone = Cup:Clone()
print(Cup:GetFullName())
print(Cup.Archivable) --Ensures another script hasn’t messed with this
print(CupClone:GetFullName())
CupClone.Parent = PlayerWhoClicked.Backpack
end)
I’m not sure if this will make any difference, but try using the code below. Let me know if you still get any errors
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cup = ReplicatedStorage:WaitForChild("Cup")
local GivePart = script.Parent:WaitForChild("GivePart")
local ClickDetector = GivePart.ClickDetector
ClickDetector.MouseClick:Connect(function(player)
local Clone = Cup:Clone()
Clone.Parent = player:WaitForChild("Backpack")
end)
Could you try these 2 code and show us the output? It could mean that there is another script interfering with the tool
local GivePart = script.Parent.GivePart
local ClickDetector = GivePart.ClickDetector
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
local Cup = ReplicatedStorage.Cup
print(Cup)
local CupClone = Cup:Clone()
print(CupClone)
CupClone.Parent = PlayerWhoClicked.Backpack
end)
local GivePart = script.Parent.GivePart
local ClickDetector = GivePart.ClickDetector
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Cup = ReplicatedStorage.Cup
ClickDetector.MouseClick:Connect(function(PlayerWhoClicked)
print(Cup.Parent)
local CupClone = Cup:Clone()
print(CupClone)
CupClone.Parent = PlayerWhoClicked.Backpack
end)