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

What is a userdata error and how can i fix it?

This is part of my gun drop script, which is supposed to make a gun spawn at the location that you died. However, it does not work as it returns the error

Players.Player.Backpack.MurderGun.ClientGunScript:66: attempt to call field 'Died' (a userdata value)

Here is my code

tool.Unequipped:connect(function(mouse)
	if mouse then	
	mouse.Icon = defaulticon
	end
end)

game.Players.LocalPlayer.Character.Humanoid.Died():connect(function()
	print("Sheriff died")
	local floatinggun = game.ReplicatedStorage.gameplay.Misc.floatinggun
	local newgun = floatinggun:Clone()
	newgun.Position = game.Players.LocalPlayer.Character.Head.CFrame.p
end)

Side note: The code is in a localscript

1 answer

✓ Accepted answer

You made a syntax error. When you connect an event to a function, you don't put a parenthesis after the event, the correct syntax is Object.event:connect(function).

To fix this, just get rid of the parenthesis after Died, like so:

game.Players.LocalPlayer.Character.Humanoid.Died:connect(function()
	--Code
end)

Hope this helped!

2 comments

0

This is not a syntax error. The code is perfectly syntactically valid -- it's just not the correct way to use the Died feature.

0

Oh, interesting

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