DetectLevel is not being changed when clearly called to be changed

DetectLevel is a NumberValue in a folder inside the Player. Whenever i is updated, DetectLevel does not update with it.

Code snippet: (I apologize for the lack of indentation)

local i = 5
local detectlevel = Player.Values.DetectLevel
detectlevel = i
								
local ok = true

repeat 

if value.Value == true then
ok = true
print(i)
i -= 1
detectlevel = i
task.wait(1)

else

print("not ok")
ok = false
debounce = false
detectlevel = 5
break
end
until i == 0 or ok == false
								
if ok == true then
local reason = " got spotted by a citizen and raised the alarm!"
local plr = game.Players:FindFirstChild(Character.Name)
				
func:Fire(plr, reason) -- func is a BindableEvent
debounce = false
end
1 Like

I bet money you’re getting errors because you’re not getting the Value of DetectLevel.
Whenever you run code along the lines of detectlevel = x, what you’re doing right now is trying to set Player.Values.DetectLevel equal to x instead of Player.Values.DetectLevel.Value.

How much you bet?

That didn’t work, what else can I try?

1 Like

if value.Value == true when did you set the value variable

1 Like

Check your output to see if you are getting an error before you try anything else. I don’t know if you’re getting an error or not, but you will get an error if you don’t fix what I mentioned

value is an unrelated value about if the Player is detectable, im certain that is not the source of the issue

I’ve checked output multiple times, no output except regular prints

So, the code is running? In that case, is this in a LocalScript or a ServerScript?

ServerScript

Summary

This text will be hidden

so i is updating and detectlevel isn’t ? isn’t that because you need to do

detectlevel.Value = i
1 Like

It’s not updating when I do that.

Show us your code with those changes, just in case you’re not doing it right

Full code

local LookPart = script.Parent.Detector
local func = game.ServerStorage.Bindables.Alarm

local debounce = false

while task.wait() do
	for _, Player in pairs(game.Players:GetPlayers()) do
		Character = Player.Character or Player.CharacterAdded:Wait()
		local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
		local Dot = (LookPart.Position - HumanoidRootPart.Position).Unit:Dot(LookPart.CFrame.LookVector)
		if Dot > 0.7 then
			local Params = RaycastParams.new()
			Params.FilterType = Enum.RaycastFilterType.Exclude
			Params:AddToFilter({LookPart,Character:GetChildren()})
			local Raycast = workspace:Raycast(LookPart.Position,-(LookPart.Position - HumanoidRootPart.Position).Unit * (LookPart.Position - HumanoidRootPart.Position).Magnitude,Params)
			if not Raycast then
				if game.Players:FindFirstChild(Character.Name) then
					local value = game.Players:FindFirstChild(Character.Name).Values.Detectable
					if script.Parent.Humanoid.Health ~= 0 then
						if value.Value == true then
							if debounce == false then
							debounce = true
								local i = 5
								local detectlevel = Player.Values.DetectLevel
								detectlevel = i
								
								local ok = true
								repeat 
									if value.Value == true then
										ok = true
										print(i)
										i -= 1
										detectlevel.Value = i
										task.wait(1)
									else
										print("not ok")
										ok = false
										debounce = false
										detectlevel.Value = 5
										break
									end
								until i == 0 or ok == false
								
								if ok == true then
									local reason = " got spotted by a citizen and raised the alarm!"
									local plr = game.Players:FindFirstChild(Character.Name)
					
									func:Fire(plr, reason)
									debounce = false
								end
							end
						end
					end
				end
				local char = Character
				local player = game.Players[char.Name]
			end
		end
	end
end

you’re setting detectlevel to i right after initializing it change it in the start as well

2 Likes

I’m almost convinced it’s because of this

local i = 5
local detectlevel = Player.Values.DetectLevel
detectlevel = i

Change it to:

local i = 5
local detectlevel = Player.Values.DetectLevel
detectlevel.Value = i -- Important! Set the *value* of DetectLevel to i, not DetectLevel itself
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.