I put playeradded in a script yet it doesn't work and comes with this error: Players.Player1.Backpack.MultiTool.LocalScript:13: attempt to call field 'PlayerAdded' (a userdata value)
Code:
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local cam = workspace.CurrentCamera local tool = script.Parent local fire = tool.Fire1 local ss = game.ReplicatedStorage local laserpos = ss.MeatLoaf:Clone() local laser = ss.Laser:Clone() local clicked = false local _ss = workspace.ss; local down = false game.Players.PlayerAdded(function()--Error laser.Parent,laserpos.Parent,mouse.TargetFilter = cam,cam,cam end) ----Different Minerals --Test mouse.Button1Down:connect(function() if clicked == true then if mouse.Target.Test.Name == "Test" then while clicked == true do mouse.Target.Test.Value.Value = mouse.Target.Test.Value.Value-5 wait(0.5) if mouse.Target.Test.Value.Value == 0 then for i= 1,math.random(3) do local iron = game.ReplicatedStorage.Iron:Clone() iron.Parent = plr.Backpack end mouse.Target:Destroy() end end end end end) ----Use Script tool.Equipped:connect(function(mouse) local _ss = workspace.ss; mouse.Button1Down:connect(function() clicked = true end) tool.Unequipped:connect(function(mouse) clicked = false fire.BrickColor = BrickColor.Black() cam.MeatLoaf.Position = _ss.Position cam.Laser.Position = _ss.Position end) mouse.Button1Up:connect(function() clicked = false down = false fire.BrickColor = BrickColor.Black() cam.MeatLoaf.Position = _ss.Position cam.Laser.Position = _ss.Position end) if script.Parent.LS.Value.Value == 0 then clicked = false down = false fire.BrickColor = BrickColor.Black() cam.MeatLoaf.Position = _ss.Position cam.Laser.Position = _ss.Position end end) while wait(0.05) do if clicked then if script.Parent.LS.Value.Value > 0 then fire.BrickColor = BrickColor.Red() game.Workspace.Camera.MeatLoaf.Position=mouse.Hit.p local dist = (laserpos.CFrame.p - fire.CFrame.p).magnitude ; laser.Size = Vector3.new(dist,0.25,.25) laser.CFrame = CFrame.new(fire.CFrame.p,laserpos.CFrame.p) * CFrame.new(0,0,-dist/2) * CFrame.Angles(0,math.rad(90),0); script.Parent.LS.Value.Value = script.Parent.LS.Value.Value - 1 laser.Transparency = 0; else clicked = false down = false fire.BrickColor = BrickColor.Black() cam.MeatLoaf.Position = _ss.Position cam.Laser.Position = _ss.Position cam.Laser.Transparency = 1 end end if clicked == false then script.Parent.LS.Value.Value = script.Parent.LS.Value.Value +2 end end
PlayerAdded
is an event, not a function. Thus, line 13:
game.Players.PlayerAdded(function() ... end)
Should be:
game.Players.PlayerAdded:Connect(function() ... end)
Players.PlayerAdded:Connect(function()
You forgot the connect