generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Search Through Workspace For Player

Previous Thread :: Next Thread 
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 09:28 AM
--This script is supposed to search through the workspace, looking for an object with a child script named after the player that just left. The script is a serverscript in the ServerScriptService. Thanks in advance!

local parent = script.Parent
local dominantPlayer
local victimPlayer
local victimPlayerChar
local workspaceChild = game.Workspace:GetChildren()

game.Players.PlayerRemoving:connect(function(player)
print("player left")
for i = 1, #workspaceChild do
print("scanning object")
if workspaceChild[i]:FindFirstChild(player.Name) then
print("found player")
dominantPlayer = player
victimPlayer = game.Players:FindFirstChild(workspaceChild[i].Name)
victimPlayerChar = workspaceChild[i]

local link = victimPlayerChar:FindFirstChild(dominantPlayer.Name)
local invincibility = victimPlayerChar.Invincibility

link:Destroy()
invincibility:Destroy()

victimPlayerChar.Humanoid.MaxHealth = 100

local returnTools = game.ReplicatedStorage.ReturnTools:Clone()
returnTools.Parent = victimPlayerChar
returnTools.Disabled = false

break
end
end
end)


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 09:29 AM
Forgot to mention, "found player" never prints.


--Online
Report Abuse
Salinas23 is not online. Salinas23
Joined: 28 Dec 2008
Total Posts: 37141
13 Nov 2016 09:32 AM
for _, child in pairs (#workspaceChild") do

I have a spider on my back.
Report Abuse
SheikhGoat is not online. SheikhGoat
Joined: 17 Mar 2011
Total Posts: 1992
13 Nov 2016 09:33 AM
Then the object most likely is not a great child of workspace but a deeper descendant or just doesn't exist at all. Since the rest of that script, atleast up to the print looks fine.
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 09:43 AM
No, I'm fairly certain that it is. I looked at the objects myself, and they all seem correct. Also, to the guy two posts up, my for loop is fine.


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 10:18 AM
Workspace
victimPlayer[player we're removing the scripts from]
dominantPlayer[script's name]
Players
dominantPlayer[player that just left]
victimPlayer[player]


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 10:25 AM
Someone, please help. Still deosn't work.


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 10:31 AM
Bump?


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 10:39 AM
Bump. Help please.


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 10:40 AM
Nobody?


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 10:50 AM
HELP


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 10:56 AM
why is nobody responding


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 11:00 AM
I've been working on this for 4 hours, why wont it work?


--Online
Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
13 Nov 2016 11:01 AM
local parent = script.Parent
local dominantPlayer
local victimPlayer
local victimPlayerChar

game.Players.PlayerRemoving:connect(function(player)
local workspaceChild = game.Workspace:GetChildren()
print("player left")
for i = 1, #workspaceChild do
print("scanning object")
if workspaceChild[i]:FindFirstChild(player.Name,true) then
print("found player")
dominantPlayer = player
victimPlayer = game.Players:FindFirstChild(workspaceChild[i].Name)
victimPlayerChar = workspaceChild[i]

local link = victimPlayerChar:FindFirstChild(dominantPlayer.Name)
local invincibility = victimPlayerChar.Invincibility

link:Destroy()
invincibility:Destroy()

victimPlayerChar.Humanoid.MaxHealth = 100

local returnTools = game.ReplicatedStorage.ReturnTools:Clone()
returnTools.Parent = victimPlayerChar
returnTools.Disabled = false

break
end
end
end)
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 11:03 AM
you are my hero and savior, it works. thanks a lot


--Online
Report Abuse
OnlineOne is online. OnlineOne
Joined: 14 Jul 2011
Total Posts: 1193
13 Nov 2016 11:04 AM
I can't believe that I missed that the workspace's children change


--Online
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image