How can i make a server tween into a local tween?

Hello! :wave:

I have just started learning to tween and I had found a tutorial to tween in a server script. Now the problem is, I want the tween in a local script, but if I put this code in a local script it doesn’t work anymore (and it doesn’t give any errors too)

Can someone explain me how I could make this server tween into a local tween or if its even possible?

Here is the script I have:

local part = script.Parent
local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
	1, --Time the tween runs
	Enum.EasingStyle.Linear, --The Easing Style of the tween
	Enum.EasingDirection.Out, --The EasingDirection of the tween
	0, --How many times the tween repeats
	false, --if the tween will reverse
	0 --How long it takes until the tween starts
)

local tween = TweenService:Create(part, tweenInfo, {Color = Color3.fromRGB(0, 255, 0)})

script.Parent.Touched:Connect(function(hit)
	tween:Play()
end)

Thanks for reading this and hopefully you can help me :smile:

2 Likes

Where are you putting the LocalScript? Assuming you’re only changing the script type to a LocalScript, they don’t run in the Workspace. Check the Developer Hub: LocalScript.

You will need a remote to send tween data to the client so that a LocalScript can consume that request in a place where it does run and then accordingly apply the tween to the object.

3 Likes

Put the local script in an area accessible to the client only such as PlayerScripts, ScreenGui, StarterPack it will not run if its in an area accessible to the server

1 Like

if you do that, the local script will run but the hole server will see it, and thats not really what I want. I want that only the player that touched the part sees it.
Do you know how I could make that possible?

What? if its in a client only area it wont run on server and its a local script so it cant anyway

1 Like

i have the local script in StarterGui and the part (thats called CheckPoint1) in Workspace
image
but if I run it with 2 players in the server, both players will see the change

hold on let me test this im very confused

1 Like

If you want it to change localy you need to specify which player sees the player the changes need to be made by a client on a local script for them to see it only

1 Like

It is because the script isnt checking if you have touched it its checking if anything has touched it therefore if something touches it it will run the code this includes other players

1 Like

what no? you dont as its a local script it only runs for them please dont reply if you have 0 idea what your talking about

1 Like

he has the script in the part. " Local scripts do not run in the workspace so simple chaning the script to a local script will not work. I would place the script in StarterPlayerScripts then wait for the part in the workspace to be loaded in." stop acting smart big chungus

Edit: He changed it below in the replies, I did not see that

1 Like

Ok but you said a localscript not a script so i got confused as local scripts only run for the client its on not all clients and you dont need to check what client the local script is running on as it will only be running on one client also that meme is dead i wasnt trying to be a smart ass i was explaining that a local script only runs on the client

2 Likes

How are you making the changes to the part since you moved the script to StarterGui can i see the updated script please

1 Like

To be completely honest with you I tried translating that from my language to English and it makes zero sense to me when I read it in English. Talking about my first reply

1 Like

you have to make the touched event detect if its the localplayer whos touching it, as leaving the code as is just makes it so whenever someone touches the part, everyones localscript runs the event.

so something like

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') == nil then return end
	local playerwhotouched = game.Players:GetPlayerFromCharacter(hit.Parent)
	
	if playerwhotouched == game.Players.LocalPlayer then
		tween:Play()
	end

end)
2 Likes

sorry that google translate is trash

2 Likes

Dude if you put your code,

local part = script.Parent
local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
	1, --Time the tween runs
	Enum.EasingStyle.Linear, --The Easing Style of the tween
	Enum.EasingDirection.Out, --The EasingDirection of the tween
	0, --How many times the tween repeats
	false, --if the tween will reverse
	0 --How long it takes until the tween starts
)

local tween = TweenService:Create(part, tweenInfo, {Color = Color3.fromRGB(0, 255, 0)})

script.Parent.Touched:Connect(function(hit)
	tween:Play()
end)

into a LocalScript in StarterPlayer.StarterPlayerScripts
and then change the variable “part” to something like part = workspace.Part
then it will tween it for the client only.

But then the problem will be that it will play when literally anything touches it. And it will also restart the tween if you touch it again.

1 Like

well if you do that, it will still show the change for the hole server

if you will do that, nothing will happen. nothing has changed then, for no one

well i though that you just had to change the first part of the script and change
local part = script.Parent → to → local part = game.Workspace.Part