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

Script that gives the new player stuff if player is me doesn't work, Why? No output?

Ok, I was trying to make a script that whenever a player joins the game, the new player is checked and if the new player is me, it gives me the tools I have in game.ReplicatedStorage Yet, it's not working and is dispensing no errors.

local rowe = game.Players:FindFirstChild("robertwoodsy5115") --nicknames robertwoodsy5115 in the code
local liljim = game.ReplicatedStorage:GetChildren() --Nicknames the children of game.ReplicatedStorage


if game.Players.PlayerAdded() then --Script gets notified if a new player joins
	game.Players:FindFirstChild("robertwoodsy5115") --checks if the new player is robertwoodsy5115
	if not robertwoodsy5115 then return end --Cancels everything if new player isn't robertwoodsy5115
else
	liljim:Clone().rowe.StarterGear --Clones children of game.ReplicatedStorage into robertwoodsy5115's starter gear
	liljim:Clone().rowe.Backpack --Does the same as the line before but with Backpack		
	end
end

1 comment

0

i say if you are only testing in studio, based on experience, PlayerAdded does not work for studio players.

2 answers

✓ Accepted answer

Uh, that's um, that's not how it works.

game:GetService("Players").PlayerAdded:Connect(function(plr) --connect the PlayerAdded event
	if plr.Name == "robertwoodsy5115" then --if name equals robertwoodsy5115
		for i,v in pairs(game:GetService("ReplicatedStorage"):GetChildren()) do --iterate repstorage's children
			if v.ClassName == "Tool" then --if it's a tool
				v:Clone().Parent = plr:WaitForChild("Backpack") --copy to backpack
				v:Clone().Parent = plr:WaitForChild("StarterGear") --and to startergear
			end
		end
	end
end)

2 comments

0

kind of took me some time staring at this, the only thing I found confusing were i,v and plr. they didn't have local.

0

lol

local Owner = {"robertwoodsy5115", 78421882} -- your name, and profile ID
local liljim = game.ReplicatedStorage:GetChildren()

game:GetService('Players').PlayerAdded:connect(function(player)
	if (player.Name == Owner[1]) or (player.UserId == Owner[2]) then 
		if liljim:IsA("Tool") then 
			liljim:Clone().Parent = player.Backpack
			liljim:Clone().Parent = player.StarterGear
		end
	end
end)

5 comments

0

nice but maybe add CharacterAdded?

0

not necessary i think.

0

how did you get my profile id, pretty creepy XD

0

To me, the simpler the code is, the easier it is to understand but code that is in more detail is more advanced

0

i have been stalking you for years. of course i know your profile id at the top of my head (:

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