Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 8 years ago

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

Log in to vote
1
Answered by 8 years ago

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!

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. BlueTaslem 18071 — 8y
0
Oh, interesting TurboFusion 1821 — 8y
Ad

Answer this question