Hey Developers! I’m currently trying to work on a unique unperformed idea for my ROBLOX game. “Flag Football”.
If you aren’t American, you wouldn’t understand, but I really need some help with this script!
I’m basically trying to make a system that spawns a flag on a characters hip, and once prompt triggered, play an animation and destroy the flag.
Heres the attachment script:
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
-- Wait for the HumanoidRootPart to be available
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
-- Clone the flag from ServerStorage
local flag = ServerStorage.Flag:Clone()
flag.Name = "Flag"
flag.Anchored = false
flag.CanCollide = false
-- Weld the flag to the player's hip
local weld = Instance.new("WeldConstraint")
weld.Part0 = humanoidRootPart
weld.Part1 = flag
weld.Parent = flag
-- Set the flag's position relative to the hip
flag.CFrame = humanoidRootPart.CFrame * CFrame.new(0, -1, 0.5)
--flag.CFrame = humanoidRootPart.CFrame * CFrame.Angles(90, 0, 0)
flag.Parent = character
end)
end)
This works perfectly, however my next script that actually destroys and plays an animation doesn’t work.
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local function createPullPrompt(flag)
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "PULL"
prompt.ObjectText = "Flag"
prompt.RequiresLineOfSight = false
prompt.MaxActivationDistance = 5
prompt.Parent = flag
return prompt
end
local function playPullAnimation(character)
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
local animator = humanoid:FindFirstChild("Animator") or Instance.new("Animator", humanoid)
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://18669346948"
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
end
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character.ChildAdded:Connect(function(child)
if child.Name == "Flag" then
local prompt = createPullPrompt(child)
prompt.Triggered:Connect(function(otherPlayer)
if otherPlayer.Team ~= player.Team then
playPullAnimation(otherPlayer.Character)
-- Remove the flag
child:Destroy()
-- Respawn the flag after 8 seconds
wait(8)
if character and character:FindFirstChild("HumanoidRootPart") then
local newFlag = ServerStorage.Flag:Clone()
newFlag.Name = "Flag"
newFlag.Anchored = false
newFlag.CanCollide = false
local weld = Instance.new("WeldConstraint")
weld.Part0 = character.HumanoidRootPart
weld.Part1 = newFlag
weld.Parent = newFlag
newFlag.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, -1, 0)
newFlag.Parent = character
createPullPrompt(newFlag)
end
end
end)
end
end)
end)
end)
This script was written by AI, and I’m not that good at technical scripting like this. But the console is clean, no errors or yellow messages. I need help ASAP please!