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

My Script Is Having an Error I Cant Fix With Removing A Character Arm?

So I Have A script Which Removes Limbs Through A GUI But The Server Script Is Having A Nil Error And I Don't Know Why. How it works is That A Local Script Send Data Through An Event And The Server Script Receives the Data then Removes That Players Limb But There's A Nil Error.

The Error Is: Workspace.LimbLoss:9: attempt to call a nil value

This Is The Server Script:

game.ReplicatedStorage.LimRemover.LimRemoveData1.OnServerEvent:Connect(function(plr,Player)
	game.ReplicatedStorage.LimRemover.LimRemoveData2.OnServerEvent:Connect(function(plr,Limb)
		local pl = game.Players:GetPlayers(Player)
		if pl then
			if Limb then
				if Limb == nil then
					print("Error In LimbLoss Limb Is Nil")
				else
					Limb:Destroy() --  This Is The Error
				end
			end
		else
			print("Error In LimbLoss")
		end
	end)
end)

Local Script (In Gui):

script.Parent.TextButton.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.LimRemover.LimRemoveData1:FireServer(script.Parent.TextBox.Text)
	wait(0.1)
	game.ReplicatedStorage.LimRemover.LimRemoveData2:FireServer("Left Arm")
end)

1 answer

✓ Accepted answer

in LocalScript on line 4 you are firing string which in main script is defined as Limb, it's a string, Destroy is not apart of string, Destroy can only be called on an Instance so if you want to destroy you need to fire the limb itself as an Instance, not it's name. In your case you just should find the limb in Character from the name so in main script you would do:

...
if pl then
	local Character = pl.Character
	local Limb = Character:FindFirstChild[Limb]
	
	if Limb == nil then
		print()
	else
		Limb:Destroy()
	end
end
...

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