Code Transformation

Hello Developers, So I made a script that’s only useful for ScreenGui’s and I want to change it so it works with a SurfaceGui. But I don’t know how to. It doesn’t show any error it just doesn’t work at all please help.

The Code:

local UIS = game:GetService('UserInputService')
local TS = game:GetService('TweenService')
local TSI = TweenInfo.new(5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local RF = script.Parent:WaitForChild("RightBG"):WaitForChild("RightFrame")
local Bind = game.StarterPlayer.StarterCharacterScripts.Binds
local Storage = game.StarterPlayer.StarterCharacterScripts.HumanVals.HumanWS
local BarValue = Instance.new('NumberValue')

BarValue.Changed:Connect(function()
	local Rot = math.clamp(BarValue.Value -180, -180, 0)
	RF.Rotation = Rot
end)

BarValue.Value = 180

local function BarIncrease()
	BarValue.Value = BarValue.Value
	local Tween1 = TS:Create(Storage, TSI, {Value = Storage.Value + 52})
	local Tween2 = TS:Create(BarValue, TSI, {Value = 180})
	Tween1:Play()
	Tween2:Play()
end

local function BarDecrease()
	BarValue.Value = BarValue.Value
	local Tween1 = TS:Create(Storage, TSI, {Value = Storage.Value - 52})
	local Tween2 = TS:Create(BarValue, TSI, {Value = 0})
	Tween1:Play()
	Tween2:Play()
end

UIS.InputBegan:Connect(function(Input, gameProccesedEvent)
	if Input.KeyCode == Enum.KeyCode[Bind.StamBind.Value] then
		BarDecrease()
	end
end)

UIS.InputEnded:Connect(function(Input, gameProccesedEvent)
	if Input.KeyCode == Enum.KeyCode[Bind.StamBind.Value] then
		BarIncrease()
	end
end)

If the SurfaceGui belongs to the workspace then the script will only work if its a server script. This is because local scripts do not execute if they are stored within the workspace.

Where is the SurfaceGui instance?

Is that model cloned/moved to the workspace when the game is running?

So it clones into the character. It’s parent is the torso inside the character

The player belongs to the workspace, so any local scripts will have to be replaced with server scripts, since local scripts don’t execute if they belong to the workspace. On the other hand, server scripts do execute if they belong to the workspace.

So I just now changed it into a server script and it still doesn’t do anything. Its suppost to move with the GUI stamina but it’s not

If the original local script makes use of features which are only available to local scripts then you won’t be able to simply copy and paste the code into a server script & expect it to work.

So I’m pretty sure that keycode only works with client scripts so how would I still support keycode?

You could use a RemoteEvent which fires the server whenever a keypress is detected.

Is there anything else in the client script that is only supported by client scripts or no?