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!
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)
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)
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)