Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Shirt script isnt working Any help? Thanks

Asked by 5 years ago

I have this shirt script that if you have a value, you should be able to get this shirt. Its giving me the shirt without the value though, any help?

game.Players.PlayerAdded:connect(function(player)

player.CharacterAdded:connect(function(character)

if player:WaitForChild("clothes").DShirt.Value>= 1 then

wait(0.1)

local d = character:GetChildren()

for i=1, #d do

if (d[i].className == "Shirt") then

d[i]:remove()

end

end

end



local h = script.Parent.DShirt:Clone()

h.Parent = character

print("dshirt should work")

wait(.1)

end)

end)
0
I have no idea where you got the DShirt if you deleted it in line 15 SoftlockedUnderZero 668 — 5y

2 answers

Log in to vote
-1
Answered by
Fad99 286 Moderation Voter
5 years ago
Edited 5 years ago

The way you looped through the table is not recommended, as you just made it harder for yourself. You should use a for i,v in pairs(TableName)do loop its built in by roblox. I is the index (the amount of iterations) and v is the value (in this case its the object).

  game.Players.PlayerAdded:connect(function(player)

    player.CharacterAdded:connect(function(character)
        if player:WaitForChild("clothes").DShirt.Value>= 1 then     
            wait(0.1)  
            local d = character:GetChildren()    
            for i,v in pairs(d) do      
                if v.ClassName == "Shirt" then      
                    v:Remove()      
                end     
            end     
        end               

        local h = script.Parent.DShirt:Clone()      
        h.Parent = player.Character     
        print("dshirt should work")     
        wait(.1)        
    end)    
end)
0
When you said for i,v inpairs(d) do, did u mean in pairs? or in Ipairs Pooglies 7 — 5y
0
in pairs sorry bout the typo Fad99 286 — 5y
0
Its alright. Pooglies 7 — 5y
0
For some reason, I still spawn with it even though I have no value? Pooglies 7 — 5y
0
You should not be using Remove / wait in your code :/ -1 User#5423 17 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago
  game.Players.PlayerAdded:connect(function(player)

    player.CharacterAdded:connect(function(character)
        if player:WaitForChild("clothes").DShirt.Value>= 1 then     
            wait(0.1)  
            local d = character:GetChildren()    
            for i,v in pairs(d) do      
                if v.ClassName == "Shirt" then      
                    v:Remove()      
                end     
            end     
        end               

        local h = script.Parent.DShirt:Clone()      
        h.Parent = player.Character     
        print("dshirt should work")     
        wait(.1)        
    end)    
end)

I tried making this let me know if it helped!

0
Crossing my fingers :D Pooglies 7 — 5y
0
Its the same as the last one, which sadly didn't work. Pooglies 7 — 5y
0
off mynameidmk 40 — 5y
0
Alright. Pooglies 7 — 5y
View all comments (3 more)
0
eh i guess i dont know then mynameidmk 40 — 5y
0
what is this ? User#5423 17 — 5y
0
The script this guy made is copied from the guy above. Pooglies 7 — 5y

Answer this question