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

How do I give players tools when they join a game due to the hats they're wearing?

I did it cheaply where I'm going to put a can't-collided brick at every spawn, each for a hat (similar to a VIP door but for hats). I was wondering what to base the hat texture on (I went by mesh). I was also wondering how I would change the two lines labeled --this is wrong, because I'm clueless about getChildren. I was also wondering about "for i=1 and #'s, but you don't have to answer that (haha). My Code:

permission = {""} -- not needed
texture = "http://www.roblox.com/asset/?id=152725777" -- Basic Egg texture...?
function checkOkToLetIn(name) 
for i = 1,#permission do 

if (string.upper(name) == string.upper(permission[i])) then return true end 
end 
return false 
end 

local Door = script.Parent

function onTouched(hit) 
print("Part Hit") 
local human = hit.Parent:findFirstChild("Humanoid") 
if (human ~= nil ) then 
getChildren()
if human.Handle.Mesh.TextureId == texture
instance.new(toolIwant)-- this is wrong
Players.human.Backpack.-- this is wrong
elseif (checkOkToLetIn(human.Parent.Name)) then 
end 
end 
end

script.Parent.Touched:connect(onTouched)

Thank you very much for your time!

1 answer

✓ Accepted answer

I am not sure whether the rest of your code will work but I changed the lines that you highlighted. You will also need to place the tool into Lighting.

permission = {""} -- not needed
texture = "http://www.roblox.com/asset/?id=152725777" -- Basic Egg texture...?
function checkOkToLetIn(name) 
for i = 1,#permission do 

if (string.upper(name) == string.upper(permission[i])) then return true end 
end 
return false 
end 

local Door = script.Parent

function onTouched(hit) 
print("Part Hit") 
local human = hit.Parent:findFirstChild("Humanoid") 
if (human ~= nil ) then 
getChildren()
if human.Handle.Mesh.TextureId == texture
game.Lighting["Tool You Want Here"]:Clone().Parent = game.Players:FindFirstChild(hit.Parent.Name) or nil
elseif (checkOkToLetIn(human.Parent.Name)) then 
end 
end 
end

script.Parent.Touched:connect(onTouched)

6 comments

0

line 19 is underlined in studio and doesn't seem to work... is there anything to do to fix it? thank you VERY much! I really appreciate it!

0

What is the error? The code on line 19 looks perfect to me. Could you paste your line 19 for me?

0

My line 19 is the same (I copy and pasted) but in studio it's underlined in red and doesn't work. Is there another way? Thank you so much

0

Can you please paste your line 19 from studio?

0

game.Lighting["tool"]:Clone().Parent = game.Players:FindFirstChild(hit.Parent.Name) or nil

0

When I paste that line in studio, I get no errors.

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