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

Help with Replicating LocalScripts?

This script is supposed to Clone another LocalScript into the player from the ReplicatedStorage. However when the LocalScript is in the player it doesn't work, why not?

teehee = script.Parent
player = game.Players.LocalPlayer

teehee.MouseButton1Down:connect(function()
	local scriptchar = game.ReplicatedStorage.RandChar:Clone()	
	scriptchar.Parent = player
end)

This is the other LocalScript in question.

math.randomseed(tick())

local skinT = {"125", "1030", "18", "119", "106", "5", "0"}
local pantsT = {"http://www.roblox.com/asset/?id=144076759","http://www.roblox.com/asset/?id=7307783"}

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character

local bColors = character:WaitForChild("Body Colors")

local newskin = skinT[math.random(1,6)]     

bColors.HeadColor = BrickColor.new(newskin)
bColors.LeftArmColor = BrickColor.new(newskin)
bColors.RightArmColor = BrickColor.new(newskin)
bColors.TorsoColor = BrickColor.new(newskin)
bColors.LeftLegColor = BrickColor.new(newskin)
bColors.RightLegColor = BrickColor.new(newskin)

local shirt = Instance.new("Shirt",character)
shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=167295776"
shirt.Name = "NewShirt"
coroutine.wrap(function()
character:WaitForChild("Shirt"):Destroy()
end)()

local pant = Instance.new("Pants",character)
pant.PantsTemplate = pantsT[math.random(1,2)]
pant.Name = "NewPants"
coroutine.wrap(function()
character:WaitForChild("Pants"):Destroy()
end)()


local head = character:WaitForChild("Head1")
head.BrickColor = BrickColor.new(newskin)

2 answers

✓ Accepted answer

Easy fix! A local script won't run inside of the player

teehee = script.Parent
player = game.Players.LocalPlayer

teehee.MouseButton1Down:connect(function()
    local scriptchar = game.ReplicatedStorage.RandChar:Clone()  
    scriptchar.Parent = player.PlayerGui --It'll run in the playerGui though
end)

Also, if you're not going to reference scriptchar then try this:

game.ReplicatedStorage.RandChar:Clone() .Parent = player.PlayerGui
teehee = script.Parent
player = game.Players.LocalPlayer
teehee.MouseButton1Down:connect(function()
    local scriptchar = game.ReplicatedStorage.RandChar:Clone() 
    scriptchar.Parent = player
function Loop((--LOOPAMOUNT))
end)

2 comments

0

Err, I don't see how this really works.

0

Try it

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