Cloning a script doesn't make it work

Does cloning a script not make it work? i’m cloning a billboardgui that has an imagegui with a script in it but the script doesn’t make the image spin. the script isn’t the problem because it works on another gui and it has no specific assaignments? is it me or is it roblox??

Seems like you’re cloning the script via the client.
What does your code look like?
And do you clone it via the client or server?

it is actually being cloned to the client, the script is originally in workspace and it’s being cloned into the client’s starterplayer folder so others don’t see it

Show me your clone script and spin script.

maybe by remoteevents or bindable events, and then whenever you have cloned the billboard gui, fire the event so the script would run again?

-- the spin script
TS = game:GetService("TweenService")
TI = TweenInfo.new(0.7,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)
script.Parent.Rotation = 0

S1 = {Rotation = 120}
S2 = {Rotation = 240}
S3 = {Rotation = 360}


Spin1 = TS:Create(script.Parent,TI,S1)
Spin2 = TS:Create(script.Parent,TI,S2)
Spin3 = TS:Create(script.Parent,TI,S3)

local function RepeatSpin()
while true do
	wait()
	Spin1:Play()
	wait(1)
	Spin2:Play()
	wait(1)
	Spin3:Play()
	wait(1)
	script.Parent.Rotation = 0
	end
end

local CORO = coroutine.create(RepeatSpin)
coroutine.resume(CORO)
--The part of the script that clones it
Connection = UIS.InputBegan:Connect(function(Key)
						Key = Key.KeyCode
						if Key == Enum.KeyCode.Space then
							if HS == Enum.HumanoidStateType.Freefall then
								if not closest[1]:FindFirstChild("BillboardGui") then
									local RealTarg = game.ReplicatedStorage["PH1--Target"].BillboardGui:Clone()
									RealTarg.Parent = closest[1]
									script["Lock On"]:Play()
									wait(1)
									RealTarg:Destroy()

I don’t think the cloning script is the issue though, because it clones everything correctly. (including the script)

The code won’t run when being parented there manually.
You should parent it to their playergui instead.

the gui is being cloned onto a part so the player can see it. (as in, it needs to appear on the part so the player can see said part) is changing it to playergui going to affect this in any way?

Only the affected player will be able to see the changes being made.
(Since you are only giving them the script, not everyone else).

the script still doesn’t play when i do this, and also the image’s position changed

i have two questions about this;
1 - how would this affect preformance?
2 - what is a bindable event? i know how to use remote events but that might be a better option

What I currently see:

  1. You are cloning a localscript from the server (to their playergui)
  2. The localscript does not run

Is this the correct information?
It will run if being parented into their playergui.

the script is a server script… now that you make me say this i think i know the issue now lol

Based on the information I have, I see no issues, unless you are missing something else.

i thought changing it to a local script would fix it, it didn’t apparently

To make this easier:

  1. Is the spin script a localscript or a serverscript?
  2. Is the cloning part a localscript or a serverscript?

Also, InputBegan is a client-sided function of UserInputService.

1 - the spin was a server script, it didn’t work as a server script so i changed it to local, same results
2 - the cloning script is in a local script

Perhaps this can help then.

Main:

local UIS = game:GetService('UserInputService')

UIS.InputBegan:Connect(function(Key)
	local KeyCode = Key.KeyCode
	if KeyCode == Enum.KeyCode.Space then
		if HS == Enum.HumanoidStateType.Freefall then -- ??
			if not closest[1]:FindFirstChild("BillboardGui") then -- ??
				local RealTarg = game.ReplicatedStorage["PH1--Target"].BillboardGui:Clone()
				RealTarg.Parent = closest[1] -- ??
				script["Lock On"]:Play()
				wait(1)
				RealTarg:Destroy()
				
				-- Disable / enable the spin script here. This just an example.
				-- To reference the script: script.Spin (Spin is inside this script).
				-- Place this in StarterPlayerScripts.
			end
		end
	end	
end)		

Spin:

-- the spin script
local TS = game:GetService("TweenService")
local TI = TweenInfo.new(0.7,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)
script.Parent.Rotation = 0

local S1 = {Rotation = 120}
local S2 = {Rotation = 240}
local S3 = {Rotation = 360}


Spin1 = TS:Create(script.Parent,TI,S1)
Spin2 = TS:Create(script.Parent,TI,S2)
Spin3 = TS:Create(script.Parent,TI,S3)

local function RepeatSpin()
	while true do
		wait()
		Spin1:Play()
		wait(1)
		Spin2:Play()
		wait(1)
		Spin3:Play()
		wait(1)
		script.Parent.Rotation = 0
	end
end

local CORO = coroutine.create(RepeatSpin)
coroutine.resume(CORO)

And yes, both scripts are localscripts.

1 Like

i just found out that i am very stupid.

i cloned the wrong script which is why it wasn’t working. sorry for the waste of time, the spin script you gave me did work though, so thank you for that

3 Likes

I assumed it did as nothing seemed wrong here.
You’re welcome anyways.