Attempt to index nil with 'Clone'

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to get it to where when I press this button it will Equip the trail and then click the button again to unequip it.

  2. What is the issue? Include screenshots / videos if possible!
    when I go to Unequip it, it gives me this error.
    image

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked at some other posts but none of them relate to my code/issue

This is my Server Script

local repStorage = game:GetService("ReplicatedStorage")
local equipTrail = repStorage.EquipTrail

equipTrail.OnServerEvent:Connect(function(plr, trailName, trail)
	if trailName then
		trailName:Destroy()
	else
		local newTrail = trail:Clone()
		newTrail.Parent = plr.Character
		local weldConst = Instance.new("WeldConstraint")
		weldConst.Parent = newTrail
		weldConst.Part0 = newTrail
		weldConst.Part1 = plr.Character.UpperTorso
		newTrail.Position = plr.Character.UpperTorso.Position
	end
end)

this is my LocalScript

local button = script.Parent
local players = game:GetService("Players")
local plr = players.LocalPlayer
local repStorage = game:GetService('ReplicatedStorage')
local trail = repStorage.RainbowTrail
local equipTrail = repStorage.EquipTrail
local removeCoins = repStorage.RemoveCoins
local changeValue = repStorage.ChangeTrailValue

button.MouseButton1Click:Connect(function()
	if plr.HasRainbowTrail.Value == false then
		if plr.Turkey.Value >= 120 then
			changeValue:FireServer(plr.HasRainbowTrail)
			removeCoins:FireServer(120)
			button.Text = "Equip"
		end
	elseif button.Text == "Unequip" then
		button.Text = "Equip"
		equipTrail:FireServer()
	elseif plr.HasRainbowTrail.Value == true then
		button.Text = "Unequip"
		equipTrail:FireServer(plr.Character:FindFirstChild("RainbowTrail"), game.ReplicatedStorage.RainbowTrail)
	end
end)
1 Like

You are sending nothing in the remote in here:

	elseif button.Text == "Unequip" then
		button.Text = "Equip"
		equipTrail:FireServer()

your function in server, accepts these arguments, player indeed, then if no trailName, goes to the else, trying to Clone() "trail", but it doesnt exist cause you didnt send it.

equipTrail.OnServerEvent:Connect(function(plr, trailName, trail)
	if trailName then
		trailName:Destroy()
	else
		local newTrail = trail:Clone() -- heres the error trail doesnt exist

Edit the function to handle the unequip, check if nothing is in arguments or if is false, proceed to

1 Like

Thanks for the help! . . . . . . … . . . . .

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.