Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make sword givers like the ones in SFOTH?

Asked by 4 years ago

I'm working on my PVP game which is based off of SFOTH, but I want to add anchored gear givers around the map. How do I do this?

2
I think you need scripts to do it. CeramicTile 847 — 4y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago

you can use touch events to see if the thing touching the part is a player then if it is a player, clone a sword into the backpack

make sure you have a sword named mySword in the replicated storage and a part named SwordGiver in the workspace.

part = game.Workspace.SwordGiver --this is a reference to the part that you touch that gives you the sword

sword = game.ReplicatedStorage.mySword --this is a reference to the sword you want to give the player

--touch event that runs whenever a player touches a part
part.Touched:Connect(function(hit)
    local player = game.Players:FindFirstChild(hit.Parent.Name)
    --check if the thing hitting the part is a player
    if player then
        --only give the sword to the player if they don't already have the sword
        if not player.Backpack:FindFirstChild(sword.Name) then
            --clone the sword from the replicated storage and give it to them
            local clonedSword = sword:Clone()

            --put the sword in the player's backpack
            clonedSword.Parent = player.Character.Backpack
        end
    end
end)


1
why don't you use :GetPlayerFromCharacter. This is more reliable programmerHere 371 — 4y
Ad

Answer this question