For some weird reason my value inside the workspace won’t change back. After I chanbge it the first time. And yes it goes through the whole script I printed it. Can someone please help me! Its supposed to be spawning boosts!
local WK = game:GetService("Workspace")
local marketplaceService = game:GetService("MarketplaceService")
local replicatedStorage = game:GetService("ReplicatedStorage")
local boostsFolder = replicatedStorage:WaitForChild("Boosts")
local mapBoostsFolder = WK:WaitForChild("Map"):WaitForChild("Boosts")
local boostSpawnPoints = WK:WaitForChild("Map"):WaitForChild("BoostsSpawnPoints")
local maxBoosts = #boostSpawnPoints:GetChildren()
local boostSpawnPointFound = false
local boost = replicatedStorage:WaitForChild("Boosts"):WaitForChild("LuckBoost")
local VIPId = 684318555
local maxSeconds = 86400
local luckBoostTime = 60
local touchDebounce = false
local debounce = false
wait(2)
while true do
wait(10)
for i,v in pairs(boostSpawnPoints:GetChildren()) do
if boostSpawnPointFound == false and v.Full.Value == false then
boostSpawnPointFound = true
boostSpawnPoint = v
boostSpawnPoint.Full.Value = true -- this is the part where it does change.
local randomPositionX = math.random(1,boostSpawnPoint.Size.X / 2)
local randomPositionZ = math.random(1,boostSpawnPoint.Size.Z / 2)
local boostClone = boost:Clone()
boostClone.Name = boost.Name
boostClone.CFrame = CFrame.new(boostSpawnPoint.Position.X + randomPositionX, boostSpawnPoint.Position.Y + 3,boostSpawnPoint.Position.Z + randomPositionZ)
boostClone.Parent = mapBoostsFolder
boostClone.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if touchDebounce == false then
touchDebounce = true
boostClone:Destroy()
if marketplaceService:UserOwnsGamePassAsync(player.UserId, VIPId) then
if player.Values.BoostLuckTime.Value + luckBoostTime * 2 > maxSeconds then
player.Values.BoostLuckTime.Value = maxSeconds
else
player.Values.BoostLuckTime.Value += luckBoostTime * 2
end
player.Values.BoostLuck.Value = 4
else
if player.Values.BoostLuckTime.Value + luckBoostTime > maxSeconds then
player.Values.BoostLuckTime.Value = maxSeconds
else
player.Values.BoostLuckTime.Value += luckBoostTime
end
player.Values.BoostLuck.Value = 2
end
wait(1)
touchDebounce = false
wait(25)
boostSpawnPoint.Full.Value = false -- here it does't cahnge, but if I do: print(boostSpawnPoint.Full.Value). It does print "true". but it doesn't change and the script does go past it.
end
end
end)
end
end
boostSpawnPointFound = false
end
-- Put this script in the object that you want to control the value
local targetValue = 10 -- Set your desired initial value here
local valueChanged = false
-- Function to handle changes to the value
local function onValueChanged(newValue)
if not valueChanged then
valueChanged = true
print("Value changed to:", newValue)
-- Add your custom logic here
-- For example, you can prevent further changes or trigger an event
else
print("Value already changed, cannot be changed again.")
end
end
-- Connect the function to the value changed event
game.Workspace.ValueChangedEvent:Connect(onValueChanged)
You are basically doing this with your script in a loop:
Waiting 10 seconds
looping through all the boostSpawnPoints
Creating a boostClone
Checking to see if boostClone is touched at that instant, but if it isn’t at that instant then touched doesn’t fire.
My point exactly. Read the rest of my post.
The touched event isn’t going to fire because the script isn’t waiting for that Touched event, it’s only checking to see if it happens at the split second the script gets to that line which is once every 10 seconds.
You are starting your while true do loop,
Waiting 10 seconds,
Looping through all the boostSpawnPoints for i,v in pairs(boostSpawnPoints:GetChildren()) do
Creating boostClone
Checking to see if boostClone is touched JUST AT THAT INSTANT, but if it isn’t at that instant then touched doesn’t fire and now the Touched event isn’t checked for another 10 seconds.
If you want proof add these prints in your script right at the touched event (the middle line is the one already in your script.
print("10 seconds has expired, checking for Touched")
boostClone.Touched:Connect(function(hit) --this is the line already in your script
print(hit.Name)
The first print line will only print if boostSpawnPointFound == false and v.Full.Value == false then. If those conditions are met then it’ll print every 10 seconds.
The second print will tell you if the Touched event fired, and print the name of the part that touches.
If the 1st one prints you are at the Touched event, but if the second one doesn’t print then it will show that your Touched event isn’t firing. Touched only fires at the moment it happens, not if those parts are still touching after they first touch.