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

why is the instance nil for my character?

thank you in advance.

why does it say the the variable is nil when it is supposed to be the local player?

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Event = ReplicatedStorage:WaitForChild("run")

local function running(player)
	local old = player.Character
	
	local data = Instance.new("StringValue",player.Character) -- stores the old character
	data.Value = player.Name
	_G.store = player.Character:Clone()
	wait()
	_G.store.Parent = ReplicatedStorage.stores
	
	
	local new = game.ReplicatedStorage:FindFirstChild("flash"):Clone()
	new:SetPrimaryPartCFrame(old.HumanoidRootPart.CFrame)
	player.Character = new
	
	new.Parent = game.Workspace
	new.Humanoid.WalkSpeed = 60
	
	new.Head.trailOuter.Enabled = true
	new.Head.trailInner.Enabled = true
	player.Character.Head.trailLight.Enabled = true
	player.Character.Head.lightningParticle.Enabled = true

	player.Character.UpperTorso.trailOuter.Enabled = true
	player.Character.UpperTorso.trailInner.Enabled = true
	player.Character.UpperTorso.trailLight.Enabled = true
	player.Character.UpperTorso.lightningParticle.Enabled = true

	player.Character.RightUpperLeg.trailOuter.Enabled = true
	player.Character.RightUpperLeg.trailInner.Enabled = true
	player.Character.RightUpperLeg.trailLight.Enabled = true
	player.Character.RightUpperLeg.lightningParticle.Enabled = true

	player.Character.RightUpperArm.trailOuter.Enabled = true
	player.Character.RightUpperArm.trailInner.Enabled = true
	player.Character.RightUpperArm.trailLight.Enabled = true
	player.Character.RightUpperArm.lightningParticle.Enabled = true

	player.Character.RightHand.trailOuter.Enabled = true
	player.Character.RightHand.trailInner.Enabled = true
	player.Character.RightHand.trailLight.Enabled = true
	player.Character.RightHand.lightningParticle.Enabled = true

	player.Character.RightFoot.trailOuter.Enabled = true
	player.Character.RightFoot.trailInner.Enabled = true
	player.Character.RightFoot.trailLight.Enabled = true
	player.Character.RightFoot.lightningParticle.Enabled = true

	player.Character.LeftUpperLeg.trailOuter.Enabled = true
	player.Character.LeftUpperLeg.trailInner.Enabled = true
	player.Character.LeftUpperLeg.trailLight.Enabled = true
	player.Character.LeftUpperLeg.lightningParticle.Enabled = true

	player.Character.LeftUpperArm.trailOuter.Enabled = true
	player.Character.LeftUpperArm.trailInner.Enabled = true
	player.Character.LeftUpperArm.trailLight.Enabled = true
	player.Character.LeftUpperArm.lightningParticle.Enabled = true

	player.Character.LeftHand.trailOuter.Enabled = true
	player.Character.LeftHand.trailInner.Enabled = true
	player.Character.LeftHand.trailLight.Enabled = true
	player.Character.LeftHand.lightningParticle.Enabled = true

	player.Character.LeftFoot.trailOuter.Enabled = true
	player.Character.LeftFoot.trailInner.Enabled = true
	player.Character.LeftFoot.trailLight.Enabled = true
	player.Character.LeftFoot.lightningParticle.Enabled = true
	
end


Event.OnServerEvent:Connect(running)

1 comment

0

use ObjectValue instead of StringValue on line 8 of the code you provided lmao

1 answer

line 8 -9:

first of all don't use parent parameter of Instance.new(), and set parent property after you set other propertoes, this is why (summary: it is slow)

PSA: Don’t use Instance.new() with parent argument

second, like greatneil80 said, you can use ObjectValue instead

anyways here is what you can replace with

local data = Instance.new("ObjectValue")
data.Value = player
data.Parent = player.Character

line 15, why use game.ReplicatedStorage when you already referenced ReplicatedStorage in line 1 :v

line 19, use workspace or game:GetService("Workspace") instead of game.Workspace. (yes, Workspace is a service. so is Players, Lighting, StarterGui etc., workspace is a global variable, like game)

you should flip line 19 and 20, to prevent unnecessary replication (which is the same reason why instance.new(class, parent) is slower than Instance.new(class))

line 24-70, why not use the new variable :v you know variables can be reused a lot of times right-

1 comment

0

the script is working, however i cannot store the local players charcter

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