Hello, I want assistance on a new Capture the flag script I am making.
Basically, when people get close to the flag, I want the flag to show 1 of 2 prompts depending on whether the user is carrying a flag model inside his Character.
The main script is a local script inside the playergui folder
Proximity prompts are located in Workspace.Game.Core.Flags.RedFlag.Handle
The script would detect when a player is near and enable/disable the prompt on the client side to run specific actions like move flag up and down the pole [global action] and clone flag model to persons character or would give points if depositing flag
This is what I have on the script right now, It does not seem to detect when player is nearby so it can enable/disable the prompts.
--[[
Made By GameHounds Interactive
Do Not Redistribute
Auguest 19th, 2024
##### ___________________ #####
]]
local ProximityPromptService = game:GetService("ProximityPromptService")
local cfr = game.Workspace.Game.CORE.Flags.Red_Flag.Handle["Capture Flag"]
local cfb = game.Workspace.Game.CORE.Flags.Blue_Flag.Handle["Capture Flag"]
local dfr = game.Workspace.Game.CORE.Flags.Red_Flag.Handle["Deposit Flag"]
local dfb = game.Workspace.Game.CORE.Flags.Blue_Flag.Handle["Deposit Flag"]
local blueflag = game.Workspace.Game.CORE.Flags:FindFirstChild("Blue_Flag")
local redflag = game.Workspace.Game.CORE.Flags:FindFirstChild("Red_Flag")
local fm = script:FindFirstChild("Flag_Model")
local range = 20
local players = game:GetService("Players")
local gamepoints = game.ReplicatedStorage.Storage.Values.Red_Game_Points
-- cf.PromptShown
-- cf.PromptHidden
function capture_flag()
-- Runs when flag captured, Puts flag model on back
cfr.Triggered = true
end
function deposit_flag()
-- Runs when flag deposited to remove flag model from back and add game points
dfr.Triggered = true
end
function captureprompt_started ()
-- Make flag start lowering if capture prompt is engaged
if cfr.PromptButtonHoldBegan == true and cfr.PromptButtonHoldBegan then
end
end
function captureprompt_abandoned ()
-- make flag reset to original position if capture prompt dis-engaged
cfr.Enabled = false
cfb.Enabled = false
dfr.Enabled = false
dfb.Enabled = false
end
while true do -- Fix code: Proxmity prompt not showing when close......
wait(0.5)
local PlayerTable = players:GetPlayers()
for _,v in pairs (PlayerTable) do
local Character = v.Character
if not Character then return end
local HRP = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Distance = (HRP.CFrame.p - redflag.Handle.CFrame.p).Magnitude
if Distance < range and Humanoid.Health > 0 then
if Character:FindFirstChild("Flag") == true then
dfr.Enabled = true
else if Character:FindFirstChild("Flag") == false then
cfr.Enabled = true
end
end
else if Distance > range then
dfr.Enabled = false
cfr.Enabled = false
end
end
end
end
Any help would be amazing!