|
Plz help me making a script that removes any accessory attached to a player when a player joins the game. |
|
|
HlKMATJoin Date: 2012-10-20 Post Count: 1360 |
local function dropHats()
local localPlayer = game:GetService("Players").LocalPlayer
if localPlayer and localPlayer.Character then
for _, obj in pairs(localPlayer.Character:GetChildren()) do
if obj:IsA("Accoutrement") then
obj.Parent = game.Workspace
end
end
end
end
game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
if not gameProcessedEvent then
if inputObject.KeyCode == Enum.KeyCode.Equals then
dropHats()
end
end
end)
|
|
HlKMATJoin Date: 2012-10-20 Post Count: 1360 |
LocalScript in the PlayerScripts
|
|
|
It works when I press the equal button and I wanted them to be destroyed so I did obj:Destroy()
but I also want them to be destroyed when a player is added not when any key is pressed..
anyway Thanks a lot :)
|
|
|
HlKMATJoin Date: 2012-10-20 Post Count: 1360 |
game.Players.PlayedAdded:connect(function(player)
if player and player.Character then
for _, obj in pairs(player.Character:GetChildren()) do
if obj:IsA("Accoutrement") then
obj.Parent = game.Workspace
end
end
end
end)
|
|
HlKMATJoin Date: 2012-10-20 Post Count: 1360 |
game.Players.PlayedAdded:connect(function(player)
if player and player.Character then
for _, obj in pairs(player.Character:GetChildren()) do
if obj:IsA("Accoutrement") then
obj:Destroy()
end
end
end
end)
ignore the script above, this is right
|
|
|
I tried same earlier but it isn't working T-T
I made a new script in server script service and wrote it/pasted
but that twitter bird and other accessories were still there. |
|
|
There's a function for this in the api under Player or Players look for it |
|
|
Couldn't find it!
RE BUMP!
Help!
On character added -- destroy char:children doesnt work as well |
|
|
doggy00Join Date: 2011-01-11 Post Count: 3571 |
game.Players.PlayerAdded:connect(function(pureya)
pureya.CharacterAdded:connect(function(kyarakuta)
repeat wait() until pureya:HasAppearanceLoaded()
for i,v in pairs(kyarakuta:GetChildren()) do
if v:IsA("Accoutrement") then
v:Destroy()
end
end
end)
repeat wait() until pureya:HasAppearanceLoaded()
for i,v in pairs(pureya.Character:GetChildren()) do
if v:IsA("Accoutrement") then
v:Destroy()
end
end
end) |
|
doggy00Join Date: 2011-01-11 Post Count: 3571 |
Forgot to mention: you should put that in a server script in Workspace or ServerScriptService, but ServerScriptService is highly recommended over Workspace. |
|
VoxxieJoin Date: 2006-08-27 Post Count: 325 |
|
|
doggy00Join Date: 2011-01-11 Post Count: 3571 |
Voxxie's way works just as well. It's pretty much the exact same thing except simplified into a single built-in function.
I wasn't aware that function existed, but either way will work. :RemoveAccessories() is most likely better to use since it saves time as far as coding goes, but both of them are around the same speed (around 0.0025 on average), so I guess it's just personal preference. |
|