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

Have I done the Local Handle script correctly?

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

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

1 comment

0

Shot dude!

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