Hello! Ive been practicing scripting a bit more and im trying to set a cap of an IntValue so that once you complete putting all the logs on the campfire you cant glitch out the system and keep the number going up. Now, this is similar to a FOR loop where you can go up by a set integer and set a starting value and an end value. But I'm pretty sure you cant do this in a FOR loop and am wondering how I would do this but I can call when to proceed.
Script: I'm trying to set the variable "campfireCount" to start at 0 and stop at 3 and going up 1 each time a player puts a log in the fire.
Important script:
if humanoid and campGaurd == false then
for campfireCounts = 0, 3, 1 do
campfireCount.Value = campfireCount.Value + 1
end
if playerLogCount.Value >= 1 then
playerLogCount.Value = playerLogCount.Value - 1
campfireCount.Value = campfireCount.Value + 1
campfirelog1.Transparency = 0
campfirelog1.CanCollide = true
print("log gave")
end
if campfireCount.value == 2 then
campfirelog2.Transparency = 0
campfirelog2.CanCollide = true
elseif campfireCount.value == 3 then
campfirelog3.Transparency = 0
campfirelog3.CanCollide = true
else
print("all logs placed")
end
Full script:
--Is there player on me
local campfire = script.Parent
local campGaurd = false
local campfires = campfire.Parent
local campfirelog1 = campfires:FindFirstChild("Log1")
local campfirelog2 = campfires:FindFirstChild("Log2")
local campfirelog3 = campfires:FindFirstChild("Log3")
local function onTouch(partTouch)
local character = partTouch.Parent
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
local playerStats = player:FindFirstChild("leaderstats")
local playerLogCount = playerStats:FindFirstChild ("Has Log")
local campfireCount = playerStats:FindFirstChild ("CampFireLogs")
if humanoid and campGaurd == false then
for campfireCounts = 0, 3, 1 do
campfireCount.Value = campfireCount.Value + 1
end
if playerLogCount.Value >= 1 then
playerLogCount.Value = playerLogCount.Value - 1
campfireCount.Value = campfireCount.Value + 1
campfirelog1.Transparency = 0
campfirelog1.CanCollide = true
print("log gave")
end
if campfireCount.value == 2 then
campfirelog2.Transparency = 0
campfirelog2.CanCollide = true
elseif campfireCount.value == 3 then
campfirelog3.Transparency = 0
campfirelog3.CanCollide = true
else
print("all logs placed")
end
campGaurd = true
wait(5)
campGaurd = false
end
end
campfire.Touched:Connect(onTouch)

4 comments
I am not sure, but I think you can do the for i = 1,1 so that the loop executes only once. You can then put it into the event or function.
That is a horrible idea.
It has worked for me when I tried to rotate an object inside a function.
Why didn't you just call what was in your loop then? What is the reason to wrap something in a for loop that won't be looped? It's just a stupid idea.