part = script.Parent
serverstorage = game:GetService("ServerStorage")
part.Touched:connect(function(hit)
if game.Players:GetRandomPlayer(hit.Parent) then
p = game.Players:GetRandomPlayer(hit.Parent)
part.BrickColor = BrickColor.new("Really red")
if not p.Backpack:findFirstChild("Sword") then --To check if the player already has a sword. If they don't then the script continues.
local sword = serverstorage:WaitForChild("Sword"):Clone()
sword.Parent = p.Backpack
end
end
end)

1 comment
Edit your post to be a reasonable title and to fix your code formatting to use the Lua code formatting option.