While true do loop only printing one string

The local script:

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)
1 Like

→ 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)

you can find out how remotes work here

I got this error on the serverscript in line 14

19:42:19.422 doorDestroyValue is not a valid member of Model “Workspace.Build.Door” - Server - Script:14

could you find doorDestroyValue in the explorer and send screenshot

you can go to explorer and search for word doorDestroyValue and take a screenshot so i can see the path of where its at

image_2024-12-24_195248342
Sorry i took so long, had dinner

also that DoorDestroyValueScript was my old script that I had problems with.

its ok no worries take your time

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)

I got this warning from line 24

19:56:38.414 DoorDestroyValue is missing from DoorPart - Server - Script:24

inside door model (the one thats in the builds folder) you could create part named “DoorPart” and update localscript to this

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 then
        if mouse.Target.Name == "DoorPart" and mouse.Target.Parent.Name == "Door" then 
		print("Mouse")
		DeletedoorRemote:FireServer(mouse.Target)
        end 
	end
end)

One question, where should the local script be, because it is in the MasterKey tool.

you could update already existing localscript to this new code

I have updated the code to my local script. But the door still doesn’t destroy

could you save the door model and tool that has localscript as rbxl and send it here and ill test and fix it for you

to save the model as file right click the model and press “Save to file”

image

Sure,

Door Model:
DoorModel.rbxm (34.7 KB)

MasterKey:
MasterKey.rbxm (11.9 KB)

1 Like

It looks like you forgot to make part named “DoorPart” inside the door model i also made some typos in the localscript but its ok it should work now

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 then
		if mouse.Target.Name == "DoorPart" and mouse.Target.Parent.Name == "Door" then 
			print("Mouse")
			DeletedoorRemote:FireServer(mouse.Target.Parent.Parent)
		end 
	end
end)

Updated door model :

DoorModel.rbxm (34.8 KB)

image

Doorpart thats inside the door model basically acts like a hitbox if player clicks it than client sends message to server and server does the value updating you could make script delete the door and etc

Would i need to remove the Click Detector in DoorPart?

no but if you want you could remove it since script doesnt really use it youcan add the rbxm file of the door model i sent you and see if it works (dont forget to put the door model into builds folder in workspace)

1 Like

This is my output. But, the door has not been destroyed.

image_2024-12-24_202343742

Since door model is being destroyed theres no point of updating value of it to true

Server script :

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeletedoorRemote = ReplicatedStorage:WaitForChild("Deletedoor")

DeletedoorRemote.OnServerEvent:Connect(function(Player,DoorModel)
	if not DoorModel:FindFirstChild("DoorDestroyValue") then 
		warn("DoorDestroyValue is missing from DoorPart")
		return
	end 

	DoorModel:Destroy()
end)
1 Like

THANK YOU!!! I appreciate you helping me with this!

1 Like

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