light = game.Workspace.light.SpotLight
pp = script.Parent.ProximityPrompt
gen_pp = game.Workspace.generator.ProximityPrompt
failed = false
count = 0
rs = game:GetService("ReplicatedStorage")
rs_battery = game.ReplicatedStorage.battery
player = game.Players.LocalPlayer
local function myClone()
local clonedPart = rs_battery:Clone()
clonedPart.Parent = game.Workspace
local bat_pp = Instance.new("ProximityPrompt")
bat_pp.Parent = clonedPart
bat_pp.Triggered:Connect(function(plr)
local tool = Instance.new("Tool")
tool.Name = "battery"
local clone = rs_battery:Clone() -- this lets it know its the model
clone.Anchored = false
clone.Name = "Handle" -- every tool has to have a handle
clone.Parent = tool -- parent the handle
tool.Parent = plr.Backpack -- telling the location
clonedPart:Destroy()
end)
end
pp.Triggered:Connect(function()
if failed == false then
light.Enabled = not light.Enabled
count = count +1
if count >= 3 then
light.Enabled = false
failed = true
count = 0
myClone()
gen_pp.Enabled = true
print"failed"
end
end
end)
gen_pp.Triggered:Connect(function(plr)
if failed == true then
failed = false
local battery_char = plr.Character:FindFirstChild("battery")
local battery_back = plr.Backpack:FindFirstChild("battery")
if battery_char ~= nil then
battery_char:Destroy()
gen_pp.Enabled = false
elseif battery_back ~= nil then
battery_back:Destroy()
gen_pp.Enabled = false
end
print"fixed"
end
end)
i’m making a light system where when they break you need to have the battery to fix them. everything is working except for the proximity prompt. i only want it to be able to be fixed with the battery. right now you can fix it whenever. which leads to more issues like multiple battries spawning if it keeps breaking an you don’t have the battery.
help appreciated