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

Anyone know how to make a item detecting script using a GUI? LocalPlayer?

Im trying to create a gui that when clicked, checks if a player has a certain shirt and if they have that shirt, give them an item. I can do the gui and item giver part I just don't know where to start on making the shirt checker, I've started with this but idek, have been on holiday for a week, so am I bit rusty... excuse that.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	if player.Shirt.ShirtTemplate == "rbxassetid://479343349" then
		print "worked"
	end

Any help would be greatly appriciated, I'm only trying to expand my knowledge so nasty comments aren't needed.

1 comment

0

Anything?

1 answer

#What you could do

  • First of all: Add the 2nd end to your function or it'll error!
  • Next, you need to get the Character, not the Player.

#Getting the Character You can use Player.Character to get the character.

local player = game.Players.LocalPlayer
print("The character for "..player.Name.." is located at "..player.Character:GetFullName())

The character for Player1 is located at Workspace.Player1

Note how it doesn't say that the character is located inside the player! The character is inside of workspace! The only reason you can do Player.Character is because Player.Character is an object value so Player.Character redirects you to the Character in workspace!


#Final Product

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
    if player.Character.Shirt.ShirtTemplate == "rbxassetid://479343349" then
        print "worked"
    end
end)


Hope it helps!

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