Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ServerScriptService.PlaceHandler:3: attempt to index nil with 'Clone' Thoughts?

I have an object that gets placed through a tool. Here is the tools script (local script):

local Mouse = game.Players.LocalPlayer:GetMouse()
local tool = script.Parent
local Equipped = false

tool.Equipped:Connect(function()
    Equipped = true
end)

tool.Unequipped:connect(function()
    Equipped = false
end)

Mouse.Button1Down:Connect(function(player)
    if Equipped then
        local Target = Mouse.Target
        Mouse.TargetFilter = game.Players.LocalPlayer.Character
        if Target.Name == "Air" then
			wait(.1)
			game.ReplicatedStorage.Place:FireServer(Target.CFrame, "Dirt")
			Target:Destoy()
		end
	end
end)

This passes info to the server so the server can save it. Here is the server script (errors on line 3 where it clones the object to be placed) :

game.ReplicatedStorage.Place.OnServerEvent:Connect(function(CdaFrame, ClonedObject)
	local clone = game.ReplicatedStorage:FindFirstChild(ClonedObject)
	clone:Clone().Parent = game.Workspace.Blocks
	clone:SetPrimaryPartCFrame(CdaFrame)
end)

Thanks, JailBreaker_13

1 comment

0

I have the object (dirt) in replicated storage, no idea why it is erroring.

1 answer

✓ Accepted answer

You get this error because your variable clone is nil. You're getting this because FindFirstChild() doesn't find anything, because you're not giving it the correct string, you've mixed up the arguments a little.

The first argument that is passed when firing from client to server is the player who fired the event. Your server script should look more like this:

game.ReplicatedStorage.Place.OnServerEvent:Connect(function(Player, CdaFrame, ClonedObject)
    local clone = game.ReplicatedStorage:FindFirstChild(ClonedObject)
    clone:Clone().Parent = game.Workspace.Blocks
    clone:SetPrimaryPartCFrame(CdaFrame)
end)

2 comments

0

And what would the local script look like? The same thing?

0

Yes. The 'Player' argument is passed automatically, you don't need to pass it yourself, only retrieve it on the server as shown in my example.

This discussion is preserved as it was. New answers, comments, and votes are closed.