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.
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)
Okay, so: my ServerSide script is in ServerScriptStorage, the event is in ReplicatedStorage and the LocalScript is in StarterPlayerScripts; still doesn’t work.
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.
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
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.