Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make my script give me an item and repeat?

Hello, I have been working on a script that allows me to be able to give a certain player an item and also make it so when they die it comes back, however the script I made won't work. Here is the script, please help.

local humanoid = game.ServerStorage.GodlyBow.Parent:FindFirstChildWhichIsA('Humanoid')
game.Players.PlayerAdded:Connect(function(plr)
	local character = game.Workspace:WaitForChild(plr.Name)
	if plr.Name == "ButterDoesFly" then
		local g = game.ServerStorage.GodlyBow:Clone() -- GodlyBow Is my tool
		g.Parent = plr.Backpack
	else
		if humanoid and humanoid.Health > 0 == true then
			repeat
		end
	end
end)

1 answer

✓ Accepted answer

You're defining the variable "humanoid" as being a parent of GodlyBow inside of ServerStorage. That means the "if humanoid and humanoid.Health > 0" is checking to see if there is a humanoid parenting the GodlyBow inside of ServerStorage. Also, you don't need an 'else' conditional since the script will end if the "if plr.Name == "ButterDoesFly then" conditional isn't true.

Here's how you'd write it:

local godly_bow = game:GetService("ServerStorage"):WaitForChild("GodlyBow");

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

players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		if plr.Name == "ButterDoesFly" then
			local g = godly_bow:Clone();
			g.Parent = plr.Backpack;
		end
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.