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
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.
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
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?
i have the local script in StarterGui and the part (thats called CheckPoint1) in Workspace
but if I run it with 2 players in the server, both players will see the change
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
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
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
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
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
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)
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.
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