Help making a sword giver like the ones in SFOTH

Hello, I am wanting to make a small pillar with a sword on the top where when the player touches the pillar, the sword on top disappears and the player receives the sword. While the player has the sword no one else can pick it up from the pillar. The sword will respawn at the pillar once the player using it dies or leaves the game. I have tried so many ways to make this and it’s all not working. Anyone have a simple solution? Thank you in advance!

1 Like

What have you tried? Maybe you can just make a few edits to make it work

1 Like

I have tried looking for tutorials and could not find anything on what I am looking for and I have tried using the Roblox Assistant which is usually really helpful but absolutely useless when helping me with this.

You can just store a current owner as the variable and connect the events, one fires if they die and others if they leave, it’ll look like this

local run_sv = game:GetService("RunService")
local player_h = nil --blank ref or you can just use ObjectValue

local dead_evt = nil --Humanoid.Died events here
local leave_evt = nil --Player leaving events

local init_sword = false
sword.AncestryChanged:Connect(function(child, parent)
  local player = player_sv:GetPlayerFromCharacter(parent)
  
  if player and player_h == nil and parent == player and not init_sword then --assign this to a player
    init_sword = true
    player_h = player
    dead_evt = player.Character.Humanoid.Died:Connect(function() --besure to call :Disconnect() after they die or simply use :Once() instead of :Connect()
      player_h = nil
      init_sword = false
    end
    
    -- do something
  end 
end

then if the current owner is either dead or left, you call a function to wait for sword to spawn

Here is an easy to work with version of that …
Just place on the workspace and test it.
SwordSpawn.rbxm (5.3 KB)

Should be easy enough to see how to add your own sword. It’s pretty generic
Download the file … Right click on Workspace in the Explorer window, then select Insert From File.
(I forgot to take the the task.wait reset test … it’s right now)

Here is the script … can be placed in ServerScriptService for security sake.

local spawn=workspace:WaitForChild("SwordSpawn")
local giver=spawn:WaitForChild("Giver")
local sword=giver:WaitForChild("Sword")
local debounce=false

local function reset()
	sword.Transparency=0
	debounce=false
end

local function onTouch(part)
	local player=game.Players:GetPlayerFromCharacter(part.Parent)
	if not player or debounce then return end

	debounce=true
	sword.Transparency=1
	local asset=game:GetService("InsertService"):LoadAsset(47433):GetChildren()[1]
	asset.Handle.Anchored=false
	asset.Parent=player.Backpack

	player.CharacterRemoving:Connect(reset)
	player.AncestryChanged:Connect(function() if not player.Parent then reset() end end)
end

giver.Touched:Connect(onTouch)