Random loot script help

Ok, I changed it to a script but still nothing.
I am sorry to put you through all this but I would not have done all this by myself

math.randomseed(tick())

script.Parent.Touched:connect(function(hit)
    print(“A”)
    if hit.ParentFindFirstChild(“Humanoid”) then
        print(“B”)
        script.Disabled = false
        local player = game.Players:FindFirstChild(hit.Parent.Name)
        local random = math.random(1,100)

        if random > 0 and random < 50 then
            print(“0-50”)
            local sword1 = game.ReplicatedStorage.sword1:Clone() 
            sword1.Parent = player.BackPack
        elseif random > 50 and random < 100 then
            print(“50-100”)
            local pistol1 = game.ReplicatedStorage.Pistol1:Clone()	
        	pistol1.Parent = player.Backpack
        end

        script.Parent:Destroy()
    end
end)

Add print and show me the output

Do you want me to test then take a screenshot with the output

ok here we go:

The error is in the print maybe your “ are wrong or something like that
Create an script and copy the:

 print(“hello world”)

Just modify the hello world into A or B, etc

ok well I found this:

Oh, change the line 5 into this

hit.Parent:FindFirstChild(“Humanoid”)

well… found this too:

Oh sorry :neutral_face:, use this:

if hit.Parent:FindFirstChild(“Humanoid”) then

well… again:

NO, change in the line 5 :slight_smile:
The third was correct

well… sorry about that one thats all me

1 Like

ok so now there is no errors and when I touched the “crate” it disappeared but gave me nothing.

@baseballcal15 Can you show me the output?

ok so here’s this:

(The rest of the output is just my tycoon stuff, and also there is stuff in my tycoons that need touch up so ignore that)

Generally you can define the player and test to see if it is a player, which removes the need for a humanoid

script.Parent.Touched:Connect(function(hit)
   local player = game.Players:GetPlayerFromCharacter(hit.Parent)
   if player then
      local randomNumber = math.random(1,100)
      if randomNumber  <= 50 then
         game.ReplicatedStorage.sword1:Clone().Parent = player.Backpack
      else
         game.ReplicatedStorage.pistol1:Clone().Parent = player.Backpack
      end
      script.Parent:Destroy()
   end
end)

wow. kingerman yours worked thank you
Also thank you to gogols who helped out through everything.

No problem, if you don’t mind marking it as the solution so people know that this has been solved :slight_smile:

just did that but thank you to you both again. :grin:

2 Likes