Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why are my scripts running poorly in-game than they are in studio?

Asked by 5 years ago

I have just recently been getting this bug.

Studio: https://gyazo.com/594ed6c464d4e3ffa3bb7e512a1a45b9

Game: https://gyazo.com/e3851953665eb0fd70c5652fdecd2a21

Does anyone know how to fix this? Does it have anything to do with the ROBLOX error code 177?

0
Go to the developer console in the game and see if there are any errors. If there are, please tell us! Mr_Unlucky 1085 — 5y
0
There are no errors :( Mellodax 2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

When testing in-studio, communication with RemoteEvents to the client are almost instant. Once you start getting in-game, it is much slower. I'm assuming you are rendering this on the server side.

Solution

In order to fix this "delay", you have to do the rendering client-side. We want the LocalPlayer to feel as if their actions are instantaneous. It will render on their screen perfectly, then tell the server that it did an action. Now the server has a couple of options.

The server can either render it and make the player who requested to render it not display it (deleting or setting transparency).

The other route is to have the server :FireClient() to the other players and have them render it on their screens.

This will make it delayed for everyone else, but instant for the player who ran it. Good luck, those effects look pretty cool.

Edit: Here is a script explaining what to do.

LocalScript

RemoteEvent.OnClientEvent:Connect(function(arg1)
    local character_who_FireServer = arg1
    local referencePoint = character_who_FireServer.Head.Position
end)

ServerScript

RemoteEvent.OnServerEvent:Connect(function(player, arg1)
    local player_who_FireServer = player
    --This event will always tell you the PlayerObject
    --that fired the remote (first parameter).
    local character_who_FireServer = arg1
    for i,v in next, game.Players:GetPlayers() do
        if (v ~= player_who_FireServer) then
            RemoteEvent:FireClient(v, character_who_FireServer)
        end
    end
end)

Now once you :FireServer(), you have to provide arguments (arg1) to send in this case we need a reference point.

local arg1 = LocalPlayer.Character
RemoteEvent:FireServer(arg1)

See how arg1 travels to the ServerScript. The ServerScript then loops through all the players except the player who fired the event. The rest of the clients will receive the information with the Character object the LocalPlayer fired. Now you can use the LocalPlayer's Character as a reference point for all the other clients.

0
Do you know of a way to access certain references that would be easy in the server script, but harder on the receiving end of a local script ( :FireAllClients() )? By this I mean the original player, because I would have to change the position of these lightning bolts based on the original player's character. Mellodax 2 — 5y
0
You could use AnimationTrack.KeyframeReached to sync the animation with the lightning effect. If the animation is played on the server as well as the lightning bolts, you can sync it pretty well. Just know the client will be delayed when it triggers the ability, but you can always cover it up (with sounds, animations, camera shakes, etc). Hope I understood what you were asking. PhantomVisual 992 — 5y
0
Yeah I understand that, it was something I tried out today. Do you know how to transfer / get parameters or like references? What I mean is like the character of the player, cause for me to do a FireAllClients, each client would have to have the same local script available, but I do not know how to make a variable that is referencing only to one player, so that I may create instances based on that Mellodax 2 — 5y
0
like how I can say local Character = Player.Character or Player.CharacterAdded:Wait(), but in the local script for the FireAllClients() how would I reference back to this original character from the server script? Mellodax 2 — 5y
View all comments (5 more)
0
So the LocalPlayer will :FireServer(Character) and the server will loop through all the players and :FireClient(otherPlayer, Character), but if otherPlayer is equal to LocalPlayer then don't fire/send. The otherPlayer will have an OnClientEvent receiving it and use the sent Character as the reference point. When you fire a remote, you can send objects, so the other clients can receive the referenc PhantomVisual 992 — 5y
0
I updated my answer explaining more about what you questioned. The names of the variables and the arguments don't have to be the same, just for explanation purpose. They do have to be in the correct positions though. PhantomVisual 992 — 5y
0
thank you :) Mellodax 2 — 5y
0
so if I did like for i,v in pairs(game.Players:GetPlayers()) do, the otherPlayer would be v? Mellodax 2 — 5y
0
It's a PlayerObject, yes. Just make sure to check if 'v' isn't the player that fired the event. PhantomVisual 992 — 5y
Ad

Answer this question