generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Help Me Fix This?

Previous Thread :: Next Thread 
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
29 Dec 2013 04:42 AM
So this script is SUPPOSED to remove a hat someone is wearing when they spawn, and replace it with another specified hat. Well, the script places the new hat, but does not remove the hat the person was wearing when he/she entered the game. Can someone help me fix it?

hatId = 0
workspace.ChildAdded:connect(function(c)
if game.Players:playerFromCharacter(c) then
local x = game:GetService("InsertService"):LoadAsset(hatId)
for _, v in ipairs(c:GetChildren()) do
if v:IsA("Accoutrement") then
v:Destroy()
end
end
for _, v in ipairs(x:GetChildren()) do
if v:IsA("Accoutrement") then
v:clone().Parent = c
end
end
end
end)
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
29 Dec 2013 05:21 AM
Put this in a local script in the starterpack

repeat wait() until game.Players.LocalPlayer.Character
things = game.Players.LocalPlayer.Character:GetChildren()
for i = 1,#things do
if things[i]:IsA("Hat") then
things[i]:Remove()
end
end
--code to insert new hat
script:remove()
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
29 Dec 2013 05:43 AM
It didn't work.

repeat wait() until game.Players.LocalPlayer.Character
things = game.Players.LocalPlayer.Character:GetChildren()
for i = 1,#things do
if things[i]:IsA("Hat") then
things[i]:Remove()
end
end
hatId = 15967743
workspace.ChildAdded:connect(function(c)
if game.Players:playerFromCharacter(c) then
local x = game:GetService("InsertService"):LoadAsset(hatId)
for _, v in ipairs(x:GetChildren()) do
if v:IsA("Accoutrement") then
v:clone().Parent = c
end
end
end
end)
script:remove()
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
29 Dec 2013 05:49 AM
repeat wait() until game.Players.LocalPlayer.Character
things = game.Players.LocalPlayer.Character:GetChildren()
for i = 1,#things do
if things[i]:IsA("Hat") then
things[i]:Remove()
end
end

hatId = 123123123
local x = game:GetService("InsertService"):LoadAsset(hatId)
for _, v in ipairs(x:GetChildren()) do
if v:IsA("Accoutrement") then
v:clone().Parent = game.Players.LocalPlayer.Character
end
end

script:remove()
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
29 Dec 2013 05:53 AM
It's still not removing the hat I already have on. It puts the new hat on though.

repeat wait() until game.Players.LocalPlayer.Character
things = game.Players.LocalPlayer.Character:GetChildren()
for i = 1,#things do
if things[i]:IsA("Hat") then
things[i]:Remove()
end
end

hatId = 15967743
local x = game:GetService("InsertService"):LoadAsset(hatId)
for _, v in ipairs(x:GetChildren()) do
if v:IsA("Accoutrement") then
v:clone().Parent = game.Players.LocalPlayer.Character
end
end

script:remove()
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
29 Dec 2013 06:08 AM
Try this:






repeat wait() until game.Players.LocalPlayer.Character:GetChildren()
things = game.Players.LocalPlayer.Character:GetChildren()
for i = 1,#things do
if things[i]:IsA("Hat") then
things[i]:Remove()
end
end

hatId = 123123123
local x = game:GetService("InsertService"):LoadAsset(hatId)
for _, v in ipairs(x:GetChildren()) do
if v:IsA("Accoutrement") then
v:clone().Parent = game.Players.LocalPlayer.Character
end
end

script:remove()
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
29 Dec 2013 06:09 AM
Nope. Still doing the same thing.

repeat wait() until game.Players.LocalPlayer.Character:GetChildren()
things = game.Players.LocalPlayer.Character:GetChildren()
for i = 1,#things do
if things[i]:IsA("Hat") then
things[i]:Remove()
end
end

hatId = 15967743
local x = game:GetService("InsertService"):LoadAsset(hatId)
for _, v in ipairs(x:GetChildren()) do
if v:IsA("Accoutrement") then
v:clone().Parent = game.Players.LocalPlayer.Character
end
end

script:remove()
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
29 Dec 2013 06:11 AM
Well, lets see here.
What is the name of the hat you are wearing?
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
29 Dec 2013 06:14 AM
Sparkle Time Fedora
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
29 Dec 2013 06:15 AM
What is the name of the hat object?
(I already knew that's what that was called -.-*)
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
29 Dec 2013 06:19 AM

try this


repeat wait() until game.Players.LocalPlayer.Character
things = game.Players.LocalPlayer.Character
things.ChildAdded:connect(function(c)
if c:IsA("Hat") then
c:Remove()
end
end)

hatId = 123123123
local x = game:GetService("InsertService"):LoadAsset(hatId)
for _, v in ipairs(x:GetChildren()) do
if v:IsA("Accoutrement") then
v:clone().Parent = game.Players.LocalPlayer.Character
end
end

script:remove()
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
29 Dec 2013 06:22 AM
wait,
Here is the end result.


repeat wait() until game.Players.LocalPlayer.Character
things = game.Players.LocalPlayer.Character
things.ChildAdded:connect(function(c)
if c:IsA("Hat") then
c:Remove()
end
end)

hatId = 123123123
local x = game:GetService("InsertService"):LoadAsset(hatId)
for _, v in ipairs(x:GetChildren()) do
if v:IsA("Accoutrement") then
v:clone().Parent = game.Players.LocalPlayer.Character
end
end
wait(10)
script:remove()
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
29 Dec 2013 06:26 AM
Now it's not working at all.
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
29 Dec 2013 06:33 AM
dont know what to tell ya man xd
Report Abuse
meSmashsta is not online. meSmashsta
Joined: 31 Jan 2013
Total Posts: 1002
29 Dec 2013 07:01 AM
1st test this by pressing f7 and after pressing that, press alt + f7
Report Abuse
TheTrueLegitBoss is not online. TheTrueLegitBoss
Joined: 27 Oct 2013
Total Posts: 74
29 Dec 2013 07:05 AM
Here



function removehatsonchar(char)
local items = char:GetChildren()
for a= 1,#items do
if items[a].ClassName=="Hat" then
items[a]:Destroy()
end
end
end

function givehat(char,id)
if char~=nil then
local hatmodel= game:GetService("InsertService"):LoadAsset(id)
if hatmodel~=nil then
local hats = hatmodel:GetChildren()
if #hats > 0 then
for a= 1,#hats do
if hats[a].ClassName=="Hat" then
hats[a].Parent = char
end
end
end
hatmodel:Destroy()
end
end
end


game:GetService("Players").PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(chr)
removehatsonchar(chr)
givehat(chr,139618147)
end)
end)

removehatsonchar(game.Players.Player1.Character)
givehat(game.Players.Player1.Character,139618147)
Report Abuse
TheTrueLegitBoss is not online. TheTrueLegitBoss
Joined: 27 Oct 2013
Total Posts: 74
29 Dec 2013 07:05 AM
woops remove the last 2 lines where i gave it to player 1
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
29 Dec 2013 06:35 PM
It didn't work.

function removehatsonchar(char)
local items = char:GetChildren()
for a= 1,#items do
if items[a].ClassName=="Hat" then
items[a]:Destroy()
end
end
end

function givehat(char,id)
if char~=nil then
local hatmodel= game:GetService("InsertService"):LoadAsset(15967743)
if hatmodel~=nil then
local hats = hatmodel:GetChildren()
if #hats > 0 then
for a= 1,#hats do
if hats[a].ClassName=="Hat" then
hats[a].Parent = char
end
end
end
hatmodel:Destroy()
end
end
end


game:GetService("Players").PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(chr)
removehatsonchar(chr)
givehat(chr,139618147)
end)
end)
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
30 Dec 2013 01:34 AM
Anyone?
Report Abuse
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
30 Dec 2013 01:36 AM
local hatId = 0 --change to hatid

local hat = game:GetService("InsertService"):LoadAsset(hatId)

game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
wait(0)
for i,v in pairs(char:GetChildren()) do
if v:IsA("Hat") then
v:Destroy()
end
end
for i,v in pairs(hat:GetChildren()) do
if v:IsA("Hat") then
v:Clone().Parent = char
end
end
end)
end)
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
30 Dec 2013 01:59 AM
Thanks! It works now.

Now I just have a new problem.

I need it to work with only certain people. :/
Report Abuse
GamerOfGames123 is not online. GamerOfGames123
Joined: 14 Jul 2012
Total Posts: 210
30 Dec 2013 03:31 AM
local hatId = 0 --change to hatid
locam removeGat = {["Persson1"]=true, ["Persson2"]=true}

local hat = game:GetService("InsertService"):LoadAsset(hatId)

game.Players.PlayerAdded:connect(function(plr)
if removeHat[plr.name] then
plr.CharacterAdded:connect(function(char)
wait(0)
for i,v in pairs(char:GetChildren()) do
if v:IsA("Hat") then
v:Destroy()
end
end
for i,v in pairs(hat:GetChildren()) do
if v:IsA("Hat") then
v:Clone().Parent = char
end
end
end
end)
end)
Report Abuse
GamerOfGames123 is not online. GamerOfGames123
Joined: 14 Jul 2012
Total Posts: 210
30 Dec 2013 03:32 AM
local hatId = 0 --change to hatid
loca removeHat = {["Persson1"]=true, ["Persson2"]=true}

local hat = game:GetService("InsertService"):LoadAsset(hatId)

game.Players.PlayerAdded:connect(function(plr)
if removeHat[plr.name] then
plr.CharacterAdded:connect(function(char)
wait(0)
for i,v in pairs(char:GetChildren()) do
if v:IsA("Hat") then
v:Destroy()
end
end
for i,v in pairs(hat:GetChildren()) do
if v:IsA("Hat") then
v:Clone().Parent = char
end
end
end
end)
end)
Report Abuse
GamerOfGames123 is not online. GamerOfGames123
Joined: 14 Jul 2012
Total Posts: 210
30 Dec 2013 03:33 AM
Here is thre real
local hatId = 0 --change to hatid
local removeHat = {["Persson1"]=true, ["Persson2"]=true}

local hat = game:GetService("InsertService"):LoadAsset(hatId)

game.Players.PlayerAdded:connect(function(plr)
if removeHat[plr.name] then
plr.CharacterAdded:connect(function(char)
wait(0)
for i,v in pairs(char:GetChildren()) do
if v:IsA("Hat") then
v:Destroy()
end
end
for i,v in pairs(hat:GetChildren()) do
if v:IsA("Hat") then
v:Clone().Parent = char
end
end
end
end)
end)
Report Abuse
Chubs1995 is not online. Chubs1995
Joined: 02 Sep 2007
Total Posts: 339
30 Dec 2013 01:02 PM
It didn't work. And the second to last line has a red line under it, but it's not telling me what the error is.

local hatId = 15967743 --change to hatid
local removeHat = {["Chubs1995"]=true}

local hat = game:GetService("InsertService"):LoadAsset(hatId)

game.Players.PlayerAdded:connect(function(plr)
if removeHat[plr.name] then
plr.CharacterAdded:connect(function(char)
wait(1)
for i,v in pairs(char:GetChildren()) do
if v:IsA("Hat") then
v:Destroy()
end
end
for i,v in pairs(hat:GetChildren()) do
if v:IsA("Hat") then
v:Clone().Parent = char
end
end
end
end)
end)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image