I have a system where at a certain playtime you get a gun
but when you die your guns go away.
so how do I make it that the guns come back
Script
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local timeplayed = Instance.new(“IntValue”)
timeplayed.Name = “PlayTime”
timeplayed.Parent = leaderstats
while true do
wait(1)
timeplayed.Value += 1
if timeplayed.Value == 50 then
local M4A1 = game.ReplicatedStorage.M4A1
local M4clone = M4A1:Clone()
M4clone.Parent = player.Backpack
elseif timeplayed.Value == 100 then
local G36C = game.ReplicatedStorage.G36C
local G36Cclone = G36C:Clone()
G36C.Parent = player.Backpack
elseif timeplayed.Value == 200 then
local HK416 = game.ReplicatedStorage.HK416
local HK416Cclone = HK416:Clone()
HK416.Parent = player.Backpack
elseif timeplayed.Value == 300 then
local RPK = game.ReplicatedStorage.RPK
local RPKCclone = RPK:Clone()
RPK.Parent = player.Backpack
elseif timeplayed.Value == 400 then
local UMP45 = game.ReplicatedStorage.UMP45
local UMP45Cclone = UMP45:Clone()
UMP45.Parent = player.Backpack
end
end
so basically the script makes a leaderstat called Play time,
and when it hits a certain time it gives you a gun
but when you respawn it doesnt work anymore.
Why don’t you just have an it statement inside the loop that increases the playtime that checks if each players playtime is greater than the amount needed for a gun? If this is true, check if the player already has the gun, if they don’t, give it to them.
All you need the change is the order in which you check the numbers (greatest to least), then check if their stat is greater than the number, not equal to it.
so like this?
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local timeplayed = Instance.new(“IntValue”)
timeplayed.Name = “PlayTime”
timeplayed.Parent = leaderstats
while true do
wait(1)
timeplayed.Value += 1
if timeplayed.Value == 400 then
local UMP45 = game.ReplicatedStorage.UMP45
local UMP45Cclone = UMP45:Clone()
UMP45.Parent = player.Backpack
elseif PlayTime <= 400 then
if timeplayed.Value == 300 then
local RPK = game.ReplicatedStorage.RPK
local RPKCclone = RPK:Clone()
RPK.Parent = player.Backpack
elseif PlayTime <= 300 then
if timeplayed.Value == 200 then
local HK416 = game.ReplicatedStorage.HK416
local HK416Cclone = HK416:Clone()
HK416.Parent = player.Backpack
elseif PlayTime <= 200 then
if timeplayed.Value == 100 then
local G36C = game.ReplicatedStorage.G36C
local G36Cclone = G36C:Clone()
G36C.Parent = player.Backpack
elseif Playtime <= 100 then
if timeplayed.Value == 50 then
local M4A1 = game.ReplicatedStorage.M4A1
local M4clone = M4A1:Clone()
M4clone.Parent = player.Backpack
I’m a little confused what PlayTime is, since you already have timeplayed. But otherwise the concept looks somewhat better, since some lines still have ==. Think of it this way, players are only going to have the exact playtime for one second, you need to give them the weapon if they have anything more than that time.
this is as far as i got i dont really know what to do
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local timeplayed = Instance.new(“IntValue”)
timeplayed.Name = “Play Time”
timeplayed.Parent = leaderstats
while true do
wait(1)
timeplayed.Value += 1
if timeplayed.Value == 50 then
local M4A1 = game.ReplicatedStorage.M4A1
local M4clone = M4A1:Clone()
M4clone.Parent = player.Backpack
elseif timeplayed >= 50 then
if timeplayed.Value == 100 then
local G36C = game.ReplicatedStorage.G36C
local G36Cclone = G36C:Clone()
G36C.Parent = player.Backpack
elseif timeplayed >= 100 then
if timeplayed.Value == 200 then
local HK416 = game.ReplicatedStorage.HK416
local HK416Cclone = HK416:Clone()
HK416.Parent = player.Backpack
elseif timeplayed.Value == 300 then
local RPK = game.ReplicatedStorage.RPK
local RPKCclone = RPK:Clone()
RPK.Parent = player.Backpack
elseif timeplayed >= 300 then
if timeplayed.Value == 400 then
local UMP45 = game.ReplicatedStorage.UMP45
local UMP45Cclone = UMP45:Clone()
UMP45.Parent = player.Backpack
Well first off you un-reversed the order, so that will give you multiple items as you go on. (Not sure how you want it.) But importantly, you have random if and elseif statements inside each other that make 0 logical sense. You should only have one condition relating to timeplayed for each required value.
Since you said you don’t know what to do, I suggest you read up on these here and here or on another tutorial.