game.Workspace.Door.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Flashlight") then game.Workspace.Door.CanCollide = false wait() else -- Else game.ReplicatedStorage.Status.Value = "Its to dark in this room maybe search for a flashlight" wait(2) game.ReplicatedStorage.Status.Value = "" end end)
So i have this script if u touch a part and u have a flashlight u can go trough but it displays the message that u need to find one everytime how to fix this?
Ok, lets try it
I already saw a lot of people missing the "equipped" function of the tools. So lets apply it here so you can know how to fix this problem again in the future!
First Step : We need to know how and where we can use the equipped() function. So lets take an expample I made.
--> Locals <-- local tool = game:GetService("ReplicatedStorage").Tool local messageP = "We are fine!" --> Code! <-- local function equipped() print(messageP) end script.Parent.Equipped:Connect(equipped) --> This will print the message when you equip the tool!
And that's how we get the "Equipped" function. We can get even a character or a Humanoid. But now we will use this even to make it like you want
Second Step : Enjoy coding! You always have to enjoy what are you doing! Play some music while you script or even play something before to be relaxed!
Lets get into the code!
--> Functions <-- local function equipped() if script.Parent.Equipped then workspace:FindFirstChild("Door").CanCollide = false wait() --> Wait time you want end end local function equippedFinished() if not script.Parent.Equipped then game:GetService("ReplicatedStorage").Status.Value = "Its to dark here! You need a lintern! Or maybe a flashlight" wait() --> Wait time you want game:GetService("ReplicatedStorage").Status.Value = "" end end --> Events <-- script.Parent.Equipped:Connect(equipped) script.Parent.Unequipped:Connect(equippedFinished) --> Errormessage <-- local warnMessage = "The script is incorrect!" pcall(warnMessage) --> That's all we need!
And that's all! Now you can enjoy your pieces of code! If this helps you let me know.
I hope my answer already solve your question. If is that the case, please accept my answer. That will help me a lot!
Keep scripting!