Currently I am releasing Moon 2060.
In this game, I have just added 4 buggies with a gun turret.
The buggies move well with Vehicle Seat, but the gun turrets never work.
I made a local script and a server script for the remote event,
but it seems my local script has something wrong
because the print() there never be displayed,
although no error message is shown.
for the next time you post, it would be best to use a code block in your post, rather than posting screenshots of the scripts. you can paste your code in your post by typing ``` --code here ```
i can see that you loop through the buggies in the folder, and try and see if the mouse was clicked in the loop. Is there a certain reason for this?
not only is that for loop inefficient, but it also serves no use, as the InputBegan function in it would not be registered since the loop would already be completed by the time the player fully loads. That loop will fire as soon as the script is loaded into the player, and since they havent sat in any of the buggies, your if statement will always return false.
you should try to find a different way to check which buggy the player is in, and then make the InputBegan function seperate from any loop
Thank you for your reply.
Yes, next time I will try to use Code Block.
The reason why I use for loop is there are 4 buggies now, but in the future it may be 10 or more. And I will put them into SpaceBuggies folder for ease management.
Fore the local script, probably there are ways to do without for loops, but I have no idea now.
Now I am just renewing the local script, but still struggling.
I want to hand over the buggy object (on which the player is in) as the second argument of FireServer(), but OnServerEvent does not recognize.
Is it possible to do that?
They aren’t referring to loops (whatever code structures you’re using), they’re referring to posting the code as text as opposed to posting it as screenshots.
Thank you for your advice. Next time I will try to use Code Block.
Btw, after I swapped the position of UserInputService event with that of for loop, it worked.
And so I close this post now.
Thank you very much for your cooperation guys!