✓ Accepted answer
This is an infinite check (use if you have no other code to execute below this function and you want the player to have a sword at all times):
local function onTouched(human)
local tool = game.ReplicatedStorage.LinkedSword
local player = game.Players:FindFirstChild(human.Parent.Name)
local h = human.Parent:FindFirstChildWhichIsA("Humanoid")
while true do
wait(2)
if human.Parent:FindFirstChild("LinkedSword") then
print("This Player has a sword")
else
print("This Player has no sword")
tool:Clone().Parent = player.BackPack
end
end
end
script.Parent.Touched:Connect(onTouched)
Note: the above script was not edited in its' entirety. It was only edited by adding a "checking" system.
Otherwise, use a short-term check (only edited lines 6 through 15):
local function onTouched(human)
local tool = game.ReplicatedStorage.LinkedSword
local player = game.Players:FindFirstChild(human.Parent.Name)
local h = human.Parent:FindFirstChildWhichIsA("Humanoid")
local i = 0
repeat
if human.Parent:FindFirstChild("LinkedSword") then
print("This Player has a sword")
else
print("This Player has no sword")
tool:Clone().Parent = player.BackPack
end
i = i+1
wait(2)
until i == 3
end
script.Parent.Touched:Connect(onTouched)
Note: the above script was not edited in its' entirety. It was only edited by adding a "checking" system.
Edited script for ServerScriptStorage:
function onPlayerAdded(plr)
local tool = game.ReplicatedStorage.LinkedSword
while true do
wait(2)
if plr.Backpack:FindFirstChild("LinkedSword") or workspace:FindFirstChild(plr.Name):FindFirstChild("LinkedSword") then
print("This Player has a sword")
else
print("This Player has no sword")
tool:Clone().Parent = plr.Backpack
end
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
Note: this script is fully edited and proofread in its' entirety.
1 comment
If my answer satisfies your question, please accept it.