Raise A Floppa Money Drop System

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 :slight_smile:

2 Likes

That happens because MoneyObj doesn’t exist. Make sure to check if your ServerStorage actually has an instance called MoneyObj.

2 Likes

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.

Could you try my script then???

1 Like

Ok give me a sec im going to try it

1 Like

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)

I just made an edit to my script, see if the edited one works better

it doesnt print anything[Char Limit]

It’s not supposed to print anything, I didn’t add that function

Oh my bad replied to the wrong person

1 Like

is it running on localscript or serverscript?

It is a local script[Char Limit]

It doesnt do anything when i try it

local scripts cannot access serverstorage, only replicatedstorage

That’s probably the problem then, make it a server script

Make it a server script, or change it from ServerStorage to ReplicatedStorage

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")

Aren’t you making a floppa that drops coins? Just put the name of the floppa you’re using in the quotations