So I was trying to make a money drop system like raise a floppa everything in the code seems to make sense but when I run the code I get error “Attempt to index nil with Clone”
local clickDetector = workspace.Pig.ClickDetector
function onMouseClick()
local money = game.ServerStorage:FindFirstChild("MoneyObj")
local moneyClone = money:Clone()
moneyClone.Parent = workspace
end
clickDetector.MouseClick:connect(onMouseClick)
Any help would be appreciated thanks
2 Likes
Katrist
(Katrist)
August 15, 2022, 11:12pm
#2
That happens because MoneyObj doesn’t exist. Make sure to check if your ServerStorage actually has an instance called MoneyObj.
2 Likes
Dfn150
(DevFunNewIdeas)
August 15, 2022, 11:24pm
#3
I agree with @Katrist , also you may want to change a couple of things, try this:
local clicker = workspace:FindFirstChild("Pig").ClickDetector
clicker.MouseClick:Connect(function()
local floppa = game.Workspace:WaitForChild("NameOfFloppa")
local money = game.ServerStorage:WaitForChild("MoneyObj"):Clone()
money.Parent = workspace
money.CFrame = floppa.CFrame + CFrame.new(0,2,5)
task.wait(0.1)
end)
EDIT: Add the new money’s CFrame
Im absolutely sure that it is in server storage.
Dfn150
(DevFunNewIdeas)
August 15, 2022, 11:25pm
#5
Could you try my script then???
1 Like
Ok give me a sec im going to try it
1 Like
Katrist
(Katrist)
August 15, 2022, 11:27pm
#7
Okay, try this then:
--//Services
local ServerStorage = game:GetService("ServerStorage")
--//Variables
local MoneyObject = ServerStorage:WaitForChild("MoneyObj")
local ClickDetector = workspace.Pig.ClickDetector
--//Functions
ClickDetector.MouseClick:Connect(function()
local newMoney = MoneyObject:Clone()
newMoney.Parent = workspace
print("Successful")
end)
Dfn150
(DevFunNewIdeas)
August 15, 2022, 11:27pm
#8
I just made an edit to my script, see if the edited one works better
it doesnt print anything[Char Limit]
Dfn150
(DevFunNewIdeas)
August 15, 2022, 11:29pm
#10
It’s not supposed to print anything, I didn’t add that function
Oh my bad replied to the wrong person
1 Like
fruferbu
(fruferbu)
August 15, 2022, 11:31pm
#12
is it running on localscript or serverscript?
It is a local script[Char Limit]
It doesnt do anything when i try it
fruferbu
(fruferbu)
August 15, 2022, 11:31pm
#15
local scripts cannot access serverstorage, only replicatedstorage
Dfn150
(DevFunNewIdeas)
August 15, 2022, 11:32pm
#16
That’s probably the problem then, make it a server script
fruferbu
(fruferbu)
August 15, 2022, 11:32pm
#17
Make it a server script, or change it from ServerStorage to ReplicatedStorage
Dfn150
(DevFunNewIdeas)
August 15, 2022, 11:33pm
#18
No, he probably has to make it a server script. Click detectors can work without a local
One thing I forgot to ask what do you mean about the part that says WaitForChild("NameOfFloppa")
Dfn150
(DevFunNewIdeas)
August 15, 2022, 11:34pm
#20
Aren’t you making a floppa that drops coins? Just put the name of the floppa you’re using in the quotations