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

Have I done the Local Handle script correctly?

Asked by
cboyce1 40
9 years ago
local Handle = game.Players.ClassName.Backpack[Samsung Galaxy Alpha].Handle

I have a feeling it's wrong.

I want the Handle to be the place of contact, not the head.

local Handle = game.Players.ClassName.Backpack[Samsung Galaxy Alpha].Handle

game.Players.PlayerAdded:connect(function(Player)
    Player.Chatted:connect(function(msg)
        if Player.Character then
            local Head = Player.Character:FindFirstChild("Head")
            if Head ~= nil then
                game:GetService("Chat"):Chat(Head, msg, math.random(0,2)) -- make a random chat color
            end
        end     
    end)
end)

Thank you so much!

1 answer

Log in to vote
1
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

The variable you've assigned with its parent as "Backpack" looks like it's read as an array, with [Samsung Galaxy Alpha] as its variable.

I recommend you use :firstFindChild(--[[InsertObjectHere]]), as it finds the first child of an object.

Also, to find the handle of a player's backpack, try and use LocalPlayer as the parent of the Backpack instead of "ClassName," as the script will try and find "ClassName" in Players (if it doesn't exist, the script will break and it will return nil).

local Handle = game.Players.LocalPlayer.Backpack:FindFirstChild("Samsung Galaxy Alpha").Handle

When using LocalPlayer, you must use a LocalScript, since LocalPlayer is a client entity.

Just a tip; if this script is in a parent that has your handle,

i.e.

game > StarterPack > Gun > Script

game > StarterPack > Gun > Handle

then do this instead:

local Handle = script.Parent.Handle
0
Shot dude! cboyce1 40 — 9y
Ad

Answer this question