i am trying to have a proximity prompt show up for a generator only for players who have a battery. please help.
Well, this is just a guess, but I this you want to use a local script. What players in specific do you want to hide it from?
if a player doesn’t have a battery than they cannot see the prompt. i found a PromptHidden() event but im not sure how id access that. or if its just a function i can call.
You can set the Enabled property of the proximity prompt to false on a localscript if the player does not have a battery.
i will try this. can i put the local script anywhere?
Put it under StarterPlayerScripts, and basically just check if the character has the battery or not on a loop. If they do, enable it, else just disable it.
could you give me an example. i’m having trouble with it. these are my variables.
local player = game.Players.LocalPlayer
local gen_pp = game.Workspace.generator.ProximityPrompt
local battery_char = player.Character:FindFirstChild("battery")
local battery_back = player.Backpack:FindFirstChild("battery")
Oh man I use to write in snake case. Anyways, it could look something like this:
local player = game.Players.LocalPlayer
local gen_pp = game.Workspace.generator.ProximityPrompt
local battery_found = false
local connections = {}
player.CharacterAdded:Connect(function(character)
connections[#connections + 1] = character.ChildAdded:Connect(function(child)
if child.Name == 'battery' and not battery_found then
battery_found = true
gen_pp.Enabled = true
end
end)
connections[#connections + 1] = character.ChildRemoving:Connect(function(child)
if child.Name == 'battery' and battery_found then
battery_found = false
gen_pp.Enabled = false
end
end)
end)
player.CharacterRemoving:Connect(function(character)
for _, connection in pairs(connections) do
connection:Disconnnect()
end
connections = {}
battery_found = false
gen_pp.Enabled = false
end)
haha what’s snake case? and dang if i showed you the loop i just wrote out you’d probably gag.
snake_case_is_where_you_write_like_this_with_no_caps
ohhh lol yeah i do that because it helps me process the information. but here’s my lights script so you know.
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)
--gen_pp.Enabled = true
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(plr)
if failed == false then
light.Enabled = not light.Enabled
count = count +1
if count >= 3 then
light.Enabled = false
failed = true
count = 0
myClone()
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)
it works man. thank you so much. i’ve been working on this script for 3 freaking ddays dudde haha