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 » Scripting Helpers
Home Search
 

Re: Player/Character Switching

Previous Thread :: Next Thread 
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 03:09 PM
I'm trying to invent a tool in which turns your character into the character you click, unfortunately, every time I test it, roblox shuts down! Here's the script:

if game.Players:GetPlayerFromCharacter(clicked.Parent) ~= nil then
local Player = game.Players:GetPlayerFromCharacter(clicked.Parent)
local Char = game.Lighting.Character:Clone()
Char.Parent = game.Workspace
Char:MoveTo(game.Players.LocalPlayer.Character.Torso.Position)
end
game.Players.LocalPlayer.Character = clicked.Parent
Player.Character = Char

'clicked' is a variable defining the mouse target.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
15 Apr 2012 03:12 PM
Is this a tool or mousedetector.. or ?

† KMXD †
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 03:13 PM
This is part of a LocalScript in a hopperbin.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 04:27 PM
Bump
Report Abuse
Narutoworl is not online. Narutoworl
Joined: 09 Jul 2008
Total Posts: 2001
15 Apr 2012 04:28 PM
Is it registering the Char as nil?
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
15 Apr 2012 04:33 PM
"Char = game.Lighting.Character:Clone()" -- Is there a Character in Lighting?
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 04:36 PM
I ran a few print statements, and it lags out at the 'GetPlayerFromCharacter'
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 04:37 PM
And yes, char is in lighting. I made this script, anyways I'm testing it on NPC's so that part of the if statement shouldn't even register.
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
15 Apr 2012 04:38 PM
Blame John.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 04:42 PM
Where's John? 0_o
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
15 Apr 2012 04:43 PM
In a KFC restaurant.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 04:53 PM
Is GetPlayrtFromCharacter() broken?
Report Abuse
breuning is not online. breuning
Joined: 30 Oct 2008
Total Posts: 4268
15 Apr 2012 04:56 PM
You can't GetPlayerFromCharacter from a NPC.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 05:22 PM
Yes, but it should return nil if the object isn't a player.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 05:23 PM
Anyways, I tested it on a server as well.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 06:53 PM
Bump
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 07:45 PM
Help!
Report Abuse
Phellem is not online. Phellem
Joined: 04 Aug 2011
Total Posts: 1984
15 Apr 2012 07:51 PM
local Char = game.Lighting.Character:Clone()
Char.Parent = game.Workspace
Char:MoveTo(game.Players.LocalPlayer.Character.Torso.Position)
end
game.Players.LocalPlayer.Character = clicked.Parent
Player.Character = Char


'Char' is cut off by the end.
The local Char does not work anymore.
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 07:59 PM
^

I already changed that. =/
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
15 Apr 2012 11:12 PM
BUMP!
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
16 Apr 2012 09:01 AM
Help...
Report Abuse
Phellem is not online. Phellem
Joined: 04 Aug 2011
Total Posts: 1984
16 Apr 2012 12:16 PM
Could you post the full script. -.-
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
16 Apr 2012 01:03 PM
local mouse = nil
local mode = "Power"
local FireReload = false
local IceReload = false
local ExplosionReload = false
local ShieldReload = false
local PowerReload = false
local PunchConnection = nil
local LPunchConnection = nil
local PunchReload = false
local LPunchReload = false
local SpyReload = false
local Player = nil
local Char = nil
function Enabled(m)
mouse = m
mouse.KeyDown:connect(onKeyDown)
mouse.Button1Down:connect(Click)
end
script.Parent.Selected:connect(Enabled)

function Unequipped()
mouse = nil
end
script.Parent.Deselected:connect(Unequipped)

function onKeyDown(key)
if key == "f" or key == "F" then
mode = "Fire"
elseif key == "q" or key == "Q" then
mode = "Ice"
elseif key == "e" or key == "E" then
mode = "Explode"
elseif key == "h" or key == "H" then
mode = "Shield"
elseif key == "p" or key == "P" then
mode = "Power"
elseif key == "t" or key == "T" then
mode = "Punch"
elseif key == "y" or key == "Y" then
mode = "LPunch"
elseif key == "c" or key == "C" then
mode = "Spy"
end
end

function Click()
local clicked = mouse.Target
if mode == "Fire" and clicked~=nil and clicked.Parent:FindFirstChild("Humanoid")~=nil and FireReload == false then
FireReload = true
local fire = Instance.new("Fire")
fire.Parent = clicked
fire.Size = 10
fire.Heat = 25
fire.Name = "Fire"
fire.Color = BrickColor.new("Navy blue").Color
fire.SecondaryColor = BrickColor.new("Bright orange").Color
fire.Archivable = false
for num = 1,50 do
clicked.Parent.Humanoid:TakeDamage(1)
wait(0.1)
fire.Heat = fire.Heat-1
end
fire:Destroy()
wait(10)
FireReload = false
elseif mode == "Ice" and clicked.Parent:FindFirstChild("Humanoid")~=nil and IceReload == false then
IceReload = true
local lasso = Instance.new("SelectionPartLasso")
lasso.Parent = game.Players.LocalPlayer.Character
lasso.Humanoid = game.Players.LocalPlayer.Character.Humanoid
lasso.Part = clicked
lasso.Color = BrickColor.new("Bright blue")
lasso.Transparency = 0
lasso.Name = "SelectionPartLasso"
lasso.Visible = true
lasso.Archivable = false
clicked.Parent.Head.Anchored = true
clicked.Parent.Head.BrickColor = BrickColor.new("Bright blue")
clicked.Parent.Head.Reflectance = 0.5
clicked.Parent.Humanoid:TakeDamage(10)
wait(1)
clicked.Parent.Head.Anchored = false
lasso:Destroy()
wait(10)
IceReload = false
elseif mode == "Explode" and ExplosionReload == false then
ExplosionReload = true
Instance.new("ForceField",game.Players.LocalPlayer.Character)
local explosion = Instance.new("Explosion")
explosion.Parent = game.Workspace
explosion.Position = game.Players.LocalPlayer.Character.Torso.Position
explosion.BlastPressure = 1000
explosion.BlastRadius = 3
explosion.ExplosionType = 0
explosion.Name = "This is obviously an Explosion."
explosion.Archivable = false
wait(0.1)
game.Players.LocalPlayer.Character.ForceField:Destroy()
wait(100)
ExplosionReload = false
elseif mode == "Shield" then
ShieldReload = true
Instance.new("ForceField",game.Players.LocalPlayer.Character)
wait(5)
game.Players.LocalPlayer.Character.ForceField:Destroy()
wait(25)
ShieldReload = false
elseif mode == "Power" and clicked.Parent:FindFirstChild("Humanoid") and PowerReload == false then
PowerReload = true
local lasso = Instance.new("SelectionPartLasso")
lasso.Parent = game.Players.LocalPlayer.Character
lasso.Humanoid = game.Players.LocalPlayer.Character.Humanoid
lasso.Part = clicked
lasso.Color = BrickColor.new("Institutional white")
lasso.Transparency = 0
lasso.Name = "SelectionPartLasso"
lasso.Visible = true
lasso.Archivable = false
wait(0.5)
lasso:Destroy()
clicked:Destroy()
wait(100)
PowerReload = false
elseif mode == "Punch" and PunchReload == false then
PunchReload = true
PunchConnection = game.Players.LocalPlayer.Character:FindFirstChild("Right Arm").Touched:connect(Punch)
local right_shoulder = game.Players.LocalPlayer.Character.Torso:FindFirstChild("Right Shoulder")
right_shoulder.CurrentAngle = 2
wait(0.3)
PunchConnection:disconnect()
wait(3)
PunchReload = false
elseif mode == "LPunch" and LPunchReload == false then
LPunchReload = true
LPunchConnection = game.Players.LocalPlayer.Character:FindFirstChild("Left Arm").Touched:connect(LPunch)
local left_shoulder = game.Players.LocalPlayer.Character.Torso:FindFirstChild("Left Shoulder")
left_shoulder.CurrentAngle = -2
wait(0.3)
LPunchConnection:disconnect()
LPunchReload = false
elseif mode == "Spy" and SpyReload == false and clicked.Parent:FindFirstChild("Humanoid") ~= nil then
SpyReload = true
if game.Players:GetPlayerFromCharacter(clicked.Parent) ~= nil then
Player = game.Players:GetPlayerFromCharacter(clicked.Parent)
Char = game.Lighting.Character:Clone()
Char.Parent = game.Workspace
Char:MoveTo(game.Players.LocalPlayer.Character.Torso.Position)
else
Char = nil
Player = nil
end
game.Players.LocalPlayer.Character = clicked.Parent
Player.Character = Char
wait(10)
SpyReload = false
end
end

function Punch(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
hit.Parent.Torso.Velocity = game.Players.LocalPlayer.Character.Torso.CFrame.lookVector * 250
hit.Parent.Humanoid:TakeDamage(20)
end
end
function LPunch(hit)
if hit.Parent:FindFirstChild("Humanoid") ~= nil then
hit.Parent.Humanoid.PlatformStand = true
hit.Parent.Humanoid:TakeDamage(20)
wait(3)
hit.Parent.Humanoid.PlatformStand = false
end
end
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
16 Apr 2012 06:17 PM
BUMP
Report Abuse
Torcus is not online. Torcus
Joined: 22 Feb 2012
Total Posts: 885
16 Apr 2012 06:20 PM
Cloning a character by just one click and making yourself them is like hat-jacker. This take 2x the scripting lines.

Nobody will do that long script you posted.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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