Hello,
So in my game, there’s a point where you’re supposed to go into a dark basement to get a screwdriver. I have an invisible .Touched part with CanCollide off in the basement so when you enter it, a flashlight GUI on your screen and a SpotLight on your Torso appear. The thing is that once you find the screwdriver and equip it down there, all of a sudden the scripts breaks for some weird reason.
Clip of what I mean:
How’s this possible? You’re still inside the part as you’re picking it up, there shouldn’t be a reason for the script to bug out.
How things are set up:
The .Touched basement part
The code inside “Script”
local zone = script.Parent
local FlashlightOn = game.Workspace.FlashlightOn
local FlashlightOff = game.Workspace.FlashlightOff
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FlashlightOn = ReplicatedStorage.FlashlightOn
local FlashlightOff = ReplicatedStorage.FlashlightOff
zone.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
if not plr.PlayerGui:FindFirstChild("GUIClonedfromtouchblock") then
local clonedgui = script.Parent:FindFirstChildOfClass("ScreenGui"):Clone()
FlashlightOn:FireClient(plr)
clonedgui.Name = "GUIClonedfromtouchblock"
clonedgui.Parent = plr.PlayerGui
script.Parent.TouchEnded:Connect(function(hit2)
if hit == hit2 then
FlashlightOff:FireClient(plr)
game.Debris:AddItem(clonedgui,0)
end
end)
end
end
end
end)
The RemoteEvents in ReplicatedStorage
The LocalScripts which make the GUI and SpotLight work
The code inside FlashlightOff
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Torso = Character:WaitForChild("Torso")
local Remote = ReplicatedStorage:WaitForChild("FlashlightOff")
local FlashlightOff = workspace.FlashlightOff
Remote.OnClientEvent:Connect(function()
FlashlightOff:Play()
task.wait()
local Light = Torso:FindFirstChild("SpotLight")
if Light then
Light:Destroy()
end
end)
The code inside FlashlightOn
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Remote = ReplicatedStorage:WaitForChild("FlashlightOn")
local FlashlightOn = workspace.FlashlightOn
Remote.OnClientEvent:Connect(function()
FlashlightOn:Play()
light = Instance.new('SpotLight')
light.Brightness = 2
light.Parent = game.Players.LocalPlayer.Character.Torso
end)
What’s with things breaking when equipping tools inside the .Touched basement part I’m talking about? I’d appreciate some explanation and help!