Tween doesn't want to work

Trying to do a tween function, when someone clicks the ui button, the tween should play, there are no errors.

Script inside StarterGui>ScreenGui>…>TextButton:

script.Parent.MouseButton1Click:Connect(function(plr)
       game.ReplicatedStorage.Tween:FireServer(plr)
end)

Script inside the part, which performs tween:

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

local tweeningInformation = TweenInfo.new(
	2,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local partProperties = {
	Orientation = Vector3.new(27.83, -86.05, -0.48)
}

local Tween = tweenService:Create(part,tweeningInformation,partProperties)

game.ReplicatedStorage.Tween.OnServerEvent:Connect(function()
	Tween:Play()
end)
2 Likes

One of the up front issues is you doing :FireServer(plr) when since its being called from a specific client the server is able to identify what client fired it automatically so you should replace :FireServer(plr) with :FireServer() and the OnServerEvent:Connect(function() to OnServerEvent:Connect(function(plr)

When you use FireServer(), you have to put the Player as the 1st argument on the server side

1 Like

I tried it, and it works . [The problem was that you forgot to put Player as the 1st arguement on the server side of the event].

try making sure that the clicked event is actually firing before you go and mess with other things. and the “plr” argument needs to be put on the “OnServerEvent” event, rather than “FireServer”

I don’t really get what you mean, by that, does that mean “FireServer(plr)” is suppose to be FireServer() and “…Connect(function(plr)” into “…Connect:(function(plr)”?

No, when you FireServer from the client, the 1st argument is automatically the player. However, when you’re calling this event on the SERVER, you have to put Player as the 1st arguement.

All you have to fix, is on the server/part script :

game.ReplicatedStorage.Tween.OnServerEvent:Connect(function(player) <— this argument always has to be the player, when you use FireServer

Tween:Play()

end)

1 Like

Can I also use plr or does it have to be player?

You can name it to whatever name you’d like. But remember that it always has to be referred to the player.

While those things are all true. It really doesn’t break it his code either way since he’s not using the parameter at all.

The first thing I noticed was that his event is named “Tween” hopefully thats actually a remote event.

The name of the variable does not matter.

When server is fired it will receive the player, and it will put into the name you give it.

remote.OnServerEvent:Connect(function(plr)
    -- This works
end)

remote.OnServerEvent:Connect(function(abc)
    -- This also works
end)

It all depends what you want to write over and over when referencing the player.

Yet this is not the issue with the code. Have you made sure the server receives the events? Tried a print()?

1 Like

The script has no error and the print works, but the part isn’t tweening at all.

Also, as @Emskipo mentioned, you should avoid naming stuff in the same name, because sometimes it can cause some errors. [In this case, everything seems to be working perfectly.]

1 Like

robloxapp-20220315-2249512.wmv (763.2 KB)
Everything seems to be working fine, what is the issue?

Where is the part located in the game?

Oh now everything, works I just had some small issues. Thanks for the help!

No problems! Make sure to mark it as a solution :slight_smile: