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

script does not run after beign cloned. Cause?

I created a tool that shoots a ball at an object with RocketPropulsion after the ball is spawned the script should clone a script in the Lighting(I tried with ReplicatedStorage too) and put it in. but after it's done the cloned script doesn't run at all.

the interessting part of the first script.(its a localscript)

local source = script.Parent
.
.
.
local missile = Instance.new("Part")
.
.
.	
missile.Parent = game.Workspace
local boomscript = game.Lighting.Randomstuff.Script:Clone()
boomscript.Parent = missile

and here is the second one(this is a normal script)

local missile = script.Parent
print("do you even run?")
print(missile.Name)
wait(0.009)

function asdhitting(asd)
	print("are you there?")
	if missile.Name == asd.Parent.Parent.Name then
		print("b1")
	else
		print("g1")
		if asd then
			print("g2")
			local hum = asd.Parent:FindFirstChild("Humanoid")
		if hum then
			print("g3")
			local Res = asd.Parent:FindFirstChild("Resist")
			if Res then
				print("b4")
				if Res.Value >= 1 then
					Res.Value = Res.Value-1
					if Res.Value <= 0 then
						Res:Destroy()
						local bodyparts = Res.Parent.Head, Res.Parent:FindFirstChild("Right Arm"), Res.Parent:FindFirstChild("Left Arm"), Res.Parent.Torso, Res.Parent:FindFirstChild("Right Leg"), Res.Parent:FindFirstChild("Left Leg")
						local victim = asd.Parent
						bodyparts.BrickColor = BrickColor.new("Red")
						victim.Humanoid.Health = victim.Humanoid.Health - 5
						if victim.Humanoid.Health <= 0 then
							local murderer = missile.Name
							print(murderer .. "killed" .. asd.Parent.Name)
						end
				end
			else
				print("g4")
				print("asdf")
				local victim = asd.Parent
				victim.Humanoid.Health = victim.Humanoid.Health - 10
				if victim.magic then
					victim.magic.Value = victim.magic.Value - 2.5
					if victim.magic.Value < 0 then
						victim.Humanoid.Health = victim.Humanoid.Health - 5
					end
				end
				if victim.Humanoid.Health <= 0 then
					local murderer = missile.Name
					print(murderer .. "killed" .. asd.Parent.Name)
				end
			end
		end
	missile:Destroy()
	end
	end
	end
	end

script.Parent.Touched:connect(asdhitting)

sorry if it's too long. and something is even stranger. this script worked correctly in the past.

Thank you.

4 comments

0

So you are cloneing a script with a server script??

0

Can you give us more details as to how you're running the local script, where you're running it, what exactly you are doing to test this script? LocalScripts do not run as being a direct descendant of workspace, you must have it in a Character, PlayerGui, Backpack, or PlayerScripts.

0

the localscript is in a tool. the tool is in the Character. i start the localscript with Activated event and the server script with touched.

0

Really i wouldn't use lighting to store things but...

1 answer

Hello.

The reason it is not running is because it wasn't disabled,so it tried running in game.Lighting (it clearly can't run there).

For example:

local boomscript = game.Lighting.Randomstuff.Script:Clone()
boomscript.Parent=missile
boomscript.Disabled=false

set the script in Lighting to be Disabled.This way,it will run fresh every time it gets cloned to the new parent.

Hope this helps!

If this is the answer you were looking for,be sure to mark it as answered!

3 comments

1

I tried it and still nothing. but thanks anyways. And i forgot to write that it works in solo studio test but not on server.

0

Regardless, scripts don't run in Lighting. The only places they will run are as a descendant of Workspace or in ServerScriptService. Additonally, Lighting should not be used as storage.

0

Use ReplicatedStorage for client access,ServerStorage for server only access.

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