Portcullis issue

Hey!

So I made portcullis for a game. They work perfectly, but sometimes they are really laggy. I used server-side tweening, I believe that’s the reason they are laggy but I can’t find a solution myself, that’s why I’m asking for help here.

This is how they work:
Below is the image of how are the portcullis made. All of the parts inside are welded with WeldConstraints to the “Move” part, then it tweens that part. The “Goal1” and the “Goal2” parts are basically just for showing the tween where to move the gate.

Here is a part of the script I made.

	if Open == false and debounce == false then
		
		debounce = true
		Sound:Play()
		tweenopen:Play()
		tweenLopen:Play()
		print("Opening...")
		tweenopen.Completed:Wait()
		Open = true
		Sound:Stop()
		debounce = false

I will appreciate anyone who replied to this and tried to help me, any help is welcome!

You mentioned it yourself, server side tweening is what makes it look laggy. A solution to this would be to use a remote event when the gate is going to open to make the client play the tween.

I may be not smart enough, but the script I made basing on your suggestion doesn’t work:
There’s a RemoteEvent, ServerScript and a LocalScript in the gate model.

EDIT: I also don’t get any errors from it.

ServerScript:

detector.MouseClick:Connect(function()
	if openvalue == false then
		openevent:FireAllClients(openvalue)
	elseif openvalue == true then
		openevent:FireAllClients(openvalue)
	end
end)

LocalScript:

local event = script.Parent.OpenEvent


event.OnClientEvent:Connect(function(openvalue)
	if openvalue == false and debounce == false then
		
		print("test")
		debounce = true
		Sound:Play()
		tweenopen:Play()
		tweenLopen:Play()
		tweenopen.Completed:Wait()
		Sound:Stop()
		debounce = false

	elseif openvalue == true and debounce == false then
		
		print("testn")
		debounce = true
		Sound:Play()
		tweenclose:Play()
		tweenLclose:Play()
		print("Closing")
		tweenclose.Completed:Wait()
		Sound:Stop()
		debounce = false

	end
end)

Are you testing this in play mode? If you’re testing using “Run” you won’t be able to see it.

Yes, I am testing this in the play mode.

Is your script in replicated storage? If so, move it to starter player scripts

Okay, so: my ServerSide script is in ServerScriptStorage, the event is in ReplicatedStorage and the LocalScript is in StarterPlayerScripts; still doesn’t work.

What does it print in the output?

I fixed some of the issues with my script variables, but now it closes only on client; when I’m changing to the server view the gate is still opened.

EDIT: nvm i may be actually wrong, let me try to test it with a 2 players server

That’s what it’s supposed to do, however I seem to have missed something. If the gate was closed before a player joined, they will see it open. To fix this, you can change the position of the gate accordingly on the client side of players who join.

Alright, it worked. But what if I want for it to work for every gate in game? Am I supposed to make a script for every gate? Or there’s another way?

EDIT: I can make it the way with making scripts for every gate, but it will be an actual pain with a big map.

You can assign the current contents of the event function to a new function variable. Whenever the event is fired, the server will send the gate object along side the ‘openvalue’ variable, and the client side will call the function you added at the beginning, and this function will apply the tween to the gate object that was provided through the RemoveEvent

I believe there’s an easier way besides tweening. Maybe constraints?

Possibly, but I feel like this is starting to go off-topic. Your original problem was tween lag.

Yeah. Now I will head to studio and fix the problem.

1 Like

Just to answer your Q, there isn’t really an easier way beyond tweening. Constraints are a pain to work with and can be unreliable. Best off using tweens.

1 Like