Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why wont this script print after getting more than 3 kills?

Okay, so basically I made this game. I want to add killstreaks, and make it to where if they get 3 kills perhaps, they get like a hat (until I make weapons for them to get at 3 kills.) But, this script wont work and I don't know what will work.

if game.Players.LocalPlayer.leaderstats.Kills.Value >3 then do
			print"SIODFJOIFJDS"
end
end

I just used print for a quick test, but it doesn't even print.

3 comments

0

Thats cause you have to check for the Kills value to change

0

like game.Players.LocalPlayer.leaderstats.Kills.Changed:Connect(function()

0

So after inside that function, would it be if Kills.NewValue > 0?

2 answers

This should print for you.

game.Players.LocalPlayer.leaderstats.Kills.Value = 5
if game.Players.LocalPlayer.leaderstats.Kills.Value >3 then do
            print"SIODFJOIFJDS"
end
end

The better way is to use a Server Script with the Changed event. Read more on the Wiki https://wiki.roblox.com/index.php?title=API:Class/IntValue/Changed

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	local intValue = Instance.new("IntValue")
	
	intValue.Name = "Kills"
	intValue.Parent = Player
	
	intValue.Changed:Connect(function(value)
		if value > 3 then
			print("Hooray, you get a hat!")
		else
			print("Nope, " .. value .. " is not enough.")
		end
	end)
	
	spawn(function()
		while wait(1) do
			intValue.Value = intValue.Value + 1
		end
	end)
end)

1 comment

0

i totally didnt think of that I always did while wait do

are you serious........... "then do", 2 ends instead of 1 and print without (), im done.

if game.Players.LocalPlayer.leaderstats.Kills.Value > 3 then
            print("SIODFJOIFJDS")
end

oh and by the way this script will only print if you already have 3 kills since you are not connecting to the value when it changes.

This discussion is preserved as it was. New answers, comments, and votes are closed.