I am trying to make a while true do loop where it checks if a value of a boolvalue is either true or false every 0.1 seconds. It prints whether if the boolvalue is either true or false, however when the game starts, the boolvalue is false (that’s correct) but, when the boolvalue turns true, it doesn’t print that the boolvalue is true, it only prints that the boolvalue is false. Any Solutions
Script:
local door = script.Parent
local doorDestroyValue = door:FindFirstChild("DoorDestroyValue")
while true do
if doorDestroyValue.Value == true then
door:Destroy()
print("Value is true")
else
print("Value is False")
end
task.wait(0.1)
end
you dont have to use a loop you could use .Changed or GetPropertyChangedSignal
try this version of script and see if it works
local door = script.Parent
local doorDestroyValue = door:WaitForChild("DoorDestroyValue")
doorDestroyValue:GetPropertyChangedSignal("Value"):Connect(function()
task.wait()
if doorDestroyValue.Value == true then
print("Value is true")
else
print("Value is false")
end
end)
Try running both codes in ServerScript. If the code that changes values and the code that recognizes the changed values are both server scripts, it will work
if the value is changed on client than those changes wont apply to server you could make a remote where client sends message to server and server updates the value
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
local DoorPart = workspace.Build.DoorPart
local DoorValue = workspace.Build.Door.DoorDestroyValue
script.Parent = localPlayer.Backpack:WaitForChild("MasterKey")
mouse.Button1Down:Connect(function()
if mouse.Target == DoorPart then
print("Mouse")
DoorValue.Value = true
end
end)
→ Create RemoteEvent on replicated storage
→ Name it “Deletedoor” or something
→ create a script in ServerScriptService
Server Script :
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeletedoorRemote = ReplicatedStorage:WaitForChild("Deletedoor")
function OnDoorValueChanged(DoorModel)
if DoorModel.doorDestroyValue.Value == true then
print("Value is true")
else
print("Value is false")
end
end
for i,v in pairs(workspace.Build:GetChildren()) do
if v.Name == "Door" then
v.doorDestroyValue:GetPropertyChangedSignal("Value"):Connect(function()
task.wait()
OnDoorValueChanged(v)
end)
end
end
DeletedoorRemote.OnServerEvent:Connect(function(Player,DoorModel)
if not DoorModel:FindFirstChild("DoorDestroyValue") then
warn("DoorDestroyValue is missing from DoorPart")
return
end
DoorModel.DoorDestroyValue.Value = true
end)
LocalScript :
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeletedoorRemote = ReplicatedStorage:WaitForChild("Deletedoor")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()
script.Parent = localPlayer.Backpack:WaitForChild("MasterKey")
mouse.Button1Down:Connect(function()
if mouse.Target and mouse.Target.Name == "DoorPart" then
print("Mouse")
DeletedoorRemote:FireServer(mouse.Target)
end
end)
oh it seems like i made a typo in the previous server script try this one
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeletedoorRemote = ReplicatedStorage:WaitForChild("Deletedoor")
function OnDoorValueChanged(DoorModel)
if DoorModel.DoorDestroyValue.Value == true then
print("Value is true")
else
print("Value is false")
end
end
for i,v in pairs(workspace.Build:GetChildren()) do
if v.Name == "Door" then
v.DoorDestroyValue:GetPropertyChangedSignal("Value"):Connect(function()
task.wait()
OnDoorValueChanged(v)
end)
end
end
DeletedoorRemote.OnServerEvent:Connect(function(Player,DoorModel)
if not DoorModel:FindFirstChild("DoorDestroyValue") then
warn("DoorDestroyValue is missing from DoorPart")
return
end
DoorModel.DoorDestroyValue.Value = true
end)