Not giving the player a weapon but also no errors?

I am trying to make a loadout system but for some reason, it will not give the player a weapon so I thought that there was an error but when I checked, nothing. Why is this happening? This is comming out of a regular script too.

Code:

script.Parent.MouseButton1Click:Connect(function()
    local plr = script.Parent.Parent.Parent.Parent.Parent.Parent
    local stat = plr.leaderstats.hiddenstats.Melee
    if stat.Value == "Sword" then
        local tool = game.ReplicatedStorage.Tools.Sword:Clone()
        tool.Parent = plr.Backpack
    end
end)

Location:
unknown (1)

1 Like

Do print(stat.Value) to see if the Stat Value is actually set to Sword

You can get the player as a mousebutton1click parameter and add a WaitForChild for the leaderstat to ensure it is loaded.

Are these values “Object values?” I would use object values so you can just set the value and clone the instance value

1 Like

Try this:

local Players =game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")
local Player = Players.LocalPlayer

local Tools = Replicated:WaitForChild("Tools")

script.Parent.MouseButton1Click:Connect(function()
    --fire a remote, do  checks on the server
end)

I just saw you are using a normal script,
tho - I really suggest using a local script + remote to do that.

But if you keep insisting using a regular script, try this:

local Replicated = game:GetService("ReplicatedStorage")

local Tools = Replicated:WaitForChild("Tools")

script.Parent.MouseButton1Click:Connect(function()
    local Player = script.Parent:FindFirstAncestorOfClass("Player")
    local leaderstats = Player:WaitForChild("leaderstats"):WaitForChild("hiddenstats").melee
    if leaderstats.Value =="Sword" then
         print(leaderstats.Value)
    end
end)

1 Like

It turns out I just had the script in the wrong spot [it was suppose to be inside the play button]. Thanks to everyone who replied to help though!