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

Why wont target get a player I click on?

Asked by 6 years ago
local tool = script.Parent
local handle = tool.Handle
local playerMouse = game.Players.LocalPlayer:GetMouse()
local currenttarget

tool.Equipped:connect (function()
    a = Instance.new("Part", game.Workspace)
    b = Instance.new("Part", game.Workspace)
    c = Instance.new("Part", game.Workspace)
    d = Instance.new("Part", game.Workspace)
    e = Instance.new("Part", game.Workspace)
    f = Instance.new("Part", game.Workspace)
    cor = Instance.new("Part", game.Workspace)

    a.Position = Vector3.new(1733.5, 9.5, 34.5)
    b.Position = Vector3.new(1724.499, 9.5, 43.5)
    c.Position = Vector3.new(1733.5, 9.5, 52.5)
    d.Position = Vector3.new(1733.5, 18.5, 43.5)
    e.Position = Vector3.new(1742.5, 9.5, 43.5)
    f.Position = Vector3.new(1733.5, 0.5, 43.5)
    cor.Position = Vector3.new(1733.999, 1.5, 43)

    a.Anchored = true
    b.Anchored = true
    c.Anchored = true
    d.Anchored = true
    e.Anchored = true
    f.Anchored = true
    cor.Anchored = true

    a.Size = Vector3.new(17, 1, 17)
    b.Size = Vector3.new(17, 1, 17)
    c.Size = Vector3.new(17, 1, 17)
    d.Size = Vector3.new(17, 1, 17)
    e.Size = Vector3.new(17, 1, 17)
    f.Size = Vector3.new(17, 1, 17)
    cor.Size = Vector3.new(2, 1, 2)

    a.Name = "a"
    b.Name = "b"
    c.Name = "c"
    d.Name = "d"
    e.Name = "e"
    f.Name = "f"
    cor.Name = "cor"

    a.Orientation = Vector3.new(-90, 0, 0)
    b.Orientation = Vector3.new(0, 0, 90)
    c.Orientation = Vector3.new(90, 0, 0)
    d.Orientation = Vector3.new(0, 0, 0)
    e.Orientation = Vector3.new(0, 0, -90)
    f.Orientation = Vector3.new(0, 0, 0)

    playerMouse.Button1Down:connect(function()
        if playerMouse.Target then
        if playerMouse.Target.Parent.ClassName == "Model" then
        currenttarget = playerMouse.Target.Parent
        Target:Destroy()
        print "hi"
    end
    end
    end)

end)

-- The error is 15:54:59.001 - Players.Player1.Backpack.Pokeball.LocalScript:59: attempt to index global 'Target' (a nil value)

How do I make it detect a player so I can destory it because I cant use target as the player - Thanks

p.s The Instance.new stuff if to make a pokeball to trap players im only trying to kill players with a click to see if it works

0
jesus christ use tables... http://wiki.roblox.com/index.php?title=Table and use loops like repeat until, to shorten your script by at least 15-30 lines... wookey12 174 — 6y

1 answer

Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
6 years ago
Edited 6 years ago

line 4 : currenttarget is undefined and you might want to edit line 57 : currenttarget = playerMouse.Target.Parent and Instance.new("Part", game.Workspace) is also depecrated

cor = Instance.new("Part")
cor.Parent = game.Workspace
0
The second argument to `Instance.new` is depcrecated. :P TheeDeathCaster 2368 — 6y
Ad

Answer this question