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

Clone Weapon when leaderstat reaches value?

Asked by 5 years ago
Edited 5 years ago

So I am working on a simulator game but have gotten stuck trying to write a script for cloning a particular weapon stored in ReplicatedStorage to the player's Backpack when their Strength reaches or goes above a specific value.

I am still learning so any help is greatly appreciated thanks!

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /

Edit: Okay, so I managed to get something to work.

Here's an example:

local tool = game.ReplicatedStorage.Weapons.AduriteKatana
local player = game.Players.LocalPlayer
local strength = player.leaderstats.Strength
local strengthneeded = 10

strength.Changed:Connect(function()

if strength.Value >= strengthneeded then
    tool:Clone().Parent = player.Backpack

end

end)

It's very basic but at least it works right?

However, this means that whenever someone gains more strength, as long as they stay above 10, it'll keep cloning the weapon.

Edit2: I seem to have found a sort of fix for this. See example:

    local weapons = game.ReplicatedStorage.Weapons
    local toola = weapons.AduriteKatana
    local toolb = weapons.BaconDagger

    local player = game.Players.LocalPlayer
    local strength = player.leaderstats.Strength
    local a,b = 10,50



    local has_toola = false
    strength.Changed:Connect(function()

    if strength.Value >= a and not has_toola then
        toola:Clone().Parent = player.Backpack
        has_toola = true
        return
    end
end)

    local has_toolb = false
    strength.Changed:Connect(function()
        if strength.Value >= b and not has_toolb then
        toolb:Clone().Parent = player.Backpack
        has_toolb = true
        return
    end
end)

And here's my last and final question (I promise :) )

So I have to add each weapon manually one by one. I have over 74 weapons lol (secretly crying) Does anyone know of a better method? Or is this just gonna be a long day.

Thanks!

0
its not exploitable to my knowledge,ive ddone some of that scripting to know whats possible and when you exploit you cant get something from the replicatedstorage unless there is a server script that connects the local script to the replicatedstorage Gameplayer365247v2 1055 — 5y
0
Ah okay I'm glad, thanks! topogigio 9 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
local weapons = game.ReplicatedStorage.Weapons



local weaponlevel = {

[10] = {

"AduriteKatana",

--"Add any weapon",

},

[50] = {

"BaconDagger",

--"Add any weapon",

},

}



local function findTool(player, toolName)

if player.Character:FindFirstChild(toolName) then

return true

end

if player.Backpack:FindFirstChild(toolName) then

return true

end

return false

end



local function checkTool(player, level)

if weaponlevel[level] then

for _, v in pairs(weaponlevel[level]) do

if findTool(player, v) == false then

if weapons:FindFirstChild(v) then

weapons[v]:Clone().Parent = player.Backpack

end

end

end

end

end



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

local a = Instance.new("Folder")

a.Name = "leaderstats"

local strength = Instance.new("NumberValue")

strength.Name = "Strength"

a.Parent = Player

strength.Parent = a

strength.Changed:Connect(function(newLevel)

checkTool(Player, newLevel)

end)

end)
Ad
Log in to vote
0
Answered by 5 years ago

local Players,neededStrenght=game:GetService"Players",10

local function onPlayerAdded(player)

local leaderstats=player:WaitForChild"leaderstats" -- ?

wait(2)

local Tool=game.ReplicatedStorage.Tool1

local val,backpack=leaderstats.Strenght,player.Backpack;

while val.Changed:Wait() do

if val.Value>=neededStrenght then

break

end

end;Tool:Clone().Parent=backpack

player.CharacterAdded:Connect(function()

Tool:Clone().Parent=player.Backpack

end)end;for i,v in ipairs(Players:GetPlayers())do onPlayerAdded(v)end

Players.PlayerAdded:Connect(onPlayerAdded)

0
Can't seem to get this one to work. topogigio 9 — 5y
Log in to vote
0
Answered by 5 years ago

if you have a player object set, it's as simple as

player.leaderstats.Value.Changed:Connect(function()
    if player.leaderstats.Value.Value > 200 then
        game.ReplicatedStorage.Weapon:Clone().Parent = player.Backpack
    end
end)
0
Yeah, I've got a clone script to work. I've left this unanswered just because I was wondering if I have to do each weapon in ReplicatedStorage manually one by one? Do you know if there is another better way to do this for a large amount of weapons or not? topogigio 9 — 5y
0
could easily loop through each weapon, and have a value in them then just check the value TheGalaxyRBLX 222 — 5y

Answer this question