Value not changing

The script below is suppose to change a STRING value string with “true” or “false”. The print(“yes”) works but it does not set the status to true/false

wait(1)
local status = game.Workspace.Door.DoorsOpen.Value
local e = script.Parent.WaitingTime

function onTouched(part)
	if part.Name == "VehicleSeat" then
		print("yes")
		status = "true"
		wait(e)
		status = "false"
	end
end

	


script.Parent.Touched:connect(onTouched)

This is an indirect change instead you should do it like this

wait(1)
local status = game.Workspace.Door.DoorsOpen
local e = script.Parent.WaitingTime

function onTouched(part)
	if part.Name == "VehicleSeat" then
		print("yes")
		status.Value = "true"
		wait(e)
		status.Value = "false"
	end
end
1 Like

maybe try this:

wait(1)
local status = game.Workspace.Door.DoorsOpen
local e = script.Parent.WaitingTime
status.Value = "true"
function onTouched(part)
	if part.Name == "VehicleSeat" then
		print("yes")
		if status.Value == "true" then
			wait(e)
			status = "false"
			if status.Value == "false" then
				wait(e)
				status.Value = "true"
				print(" w")
			end
		end
		
	end
end
script.Parent.Touched:connect(onTouched)



1 Like

if the other one doesen´t work. i recomment trying this:

wait(1)
local status = game.Workspace.Door.DoorsOpen
local e = script.Parent.WaitingTime
status.Value = "true"
script.Parent.Touched:Connect(function(part)
	if part.Name == "VehicleSeat" then
		print("yes")
		if status.Value == "true" then
			wait(e)
			status = "false"
			if status.Value == "false" then
				wait(e)
				status.Value = "true"
				
			end
		end

	end
end)

1 Like

You are storing the value of DoorsOpen, which means that changing the variable’s data to “true” will not affect the DoorsOpen.Value, only the variable, since what you stored is not an object. Refer to @aliaun125’s post:

What you did was something like this:

local object = { Value = 0 }
local objectValue = object.Value

objectValue = 1

Printing the result of object.Value will still be 0. Instead it should be this:

object.Value = 1
1 Like

Thank you for all the solutions. I will be trying them out rn

1 Like

if that doesen´t work, try using bool value to set the value to true or false!

1 Like

image_2022-12-03_150620887

still remains false (nothing changed)

try using a bool value to set the value to true or false!

I have doubled check and everything seems to be correct

image_2022-12-03_151054304

The yes is still printed too

That depends on the amount of seconds on the variable e, if the seconds is about 0.1 then you would hardly notice it. If that was not the case, then I have no idea what exactly caused it to not work; testing that on my end would obviously work without even trying; this is just basic common sense.

E is always at 10 seconds though

if i use BoolValues instead of using a string would it work

1 Like

try this:

wait(1)
local status = game.Workspace.Door.DoorsOpen
local e = script.Parent.WaitingTime
script.Parent.Touched:Connect(function(part, hit)
	status.Value = "true"
		if hit and hit.Parent:FindFirstChild("Humanoid") 
 or part.Name == "VehicleSeat" then
		print("yes")
		if status.Value == "true" then
			wait(e)
			status = "false"
			if status.Value == "false" then
				print("no")
				wait(e)
				status.Value = "true"
			end
			

		end
		
		
	end
end)
1 Like

No, if the current object is not working, neither is the BoolValue. I made a little demo, and like I said before, it obviously works. The code is almost the same:

local status = script.Parent.Status

script.Parent.Touched:Connect(function()
	status.Value = true
	task.wait(10)
	status.Value = false
end)

It could be because of the variable status that you are accessing which is game.Workspace.Door.DoorsOpen could be different from what you are lookng at. You did say that it does print “yes” on the terminal this must be the case.

1 Like

this musst be working;


	wait(1)
	local status = game.Workspace.Door.DoorsOpen.Value
	local e = script.Parent.WaitingTime

script.Parent.Touched:Connect(function(part)
		if part.Name == "VehicleSeat" then
			print("yes")
		status = "true"
		else
			wait(e)
			status = "false"
		end
end)

1 Like

I found out what went wrong. I am stupid. The e variable is the WaitingTime object, not the value. So when the wait(e) is just wait(0)

2 Likes

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