How do i make it so when i go in a certain area, i get a sword

sorry if this sounds dumb, and its extremely simple, im sorry, i cant think of it atm, please help if possible :smiley:

3 Likes

So, I suggest using events. If your certain area is a part, then insert a script with the following code:

function giveSword()
—code to give sword. i do not know where u have your sword and how u want to do this. i am leaving the rest to u with this function.—

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local player = game.Players:GtePlayerFromCharacter(hit.Parent)
giveSword()
end)

3 Likes

Sorry for not formatting the code. You might also to keep in mind though that this code might not work since i didnt test it.

2 Likes

didnt work sadly, not sure what to do for this rn , but ty :smiley:

1 Like

Don’t worry about it! There’s no such thing (mostly) as a dumb question.

You can check that if the player enters a certain Region3, a sword is cloned from ReplicatedStorage and parented to the player in the region.

If you’re not aware of reigon3’s, I know that TheDevKing (a YouTube channel) has a great video on the topic.

1 Like

Oof sorry about that. I did search youtube though and found a video that I thought might help you. Check it out if you are still in need of help.

Link:

2 Likes

is there a way to make it where when your off the part it takes said-item away? (aka ClassicSword)

2 Likes

ItemName:Destroy
That will get rid of the sword.

2 Likes

Also adding to Ulxqra, use the event TouchEnded

1 Like

I recommend you look into this, https://devforum.roblox.com/t/zone-retrieving-players-within-an-area-zone/397465 .This will get you pointed into the right direction but you would have to tweak some code to fit what you desire. Not sure if you want the sword to disappear when exiting the area, but you would have to do something like that. I would explain what i tweaked to create this, as it was not much, but it simply requires cloning the sword from ServerStorage and parenting it to player when entered.
Here’s something I put together that might help.
SwordArea.rbxl (28.1 KB)

If you don’t want the player to have the tool removed when out of area, simply delete this line "Sword Area:Destroy() in the server script. Edit, I used the above link and tweaked it.

1 Like

Put a Script under the Part and change the source to this:

local part = script.Parent;

local replicatedStorage = game:GetService("RelpicatedStorage"); --Put your item under ReplicatedStorage.

local tool = replicatedStorage:FindFirstChild("Tool"); --Reference your tool.

local function on_Touch(hit)

 if hit.Parent.Humanoid ~= nil then
    
   local character = hit.Parent;

   local players = game:GetService("Players");

   local player = players:GetPlayerFromCharacter(character);

    for _, v in ipairs(player:GetChildren()) do
      
       if tostring(v.Name) == "Backpack" then

          if not v:FindFirstChild("Tool") then --Reference 'Tool' by your Tool's name.

             local toolClone = tool:Clone()
           
             toolClone.Parent = v
          end
       end
    end
end

end

part.Touched:Connenct(on_Touch)

1 Like