So im trying to make a system that spawns a “Lucky block” and inside the lucky block it uses a script that fires an event to a client. The thing is the client does not even know about the lucky block spawn or the event since its a local script. I heard this thing about filtering enabled but you cant turn it off anymore. how would i spawn a part that both the local script and the server script can see?
If you just spawn the block on the server, it will replicate to all clients, and by default everyone will see it.
If you need for only specific players to see the block, but it has to exist on the server for some reason, you can spawn it on the server invisible and uncollidable, and then just have your client script make it visible only on certain players’ clients.
If the server doesn’t need to have the block at all, you can just send a RemoteEvent from server to the desired clients to spawn the block client-side only, and then have a RunContext.Client script in the block (or a LocalScript in an executable place that handles interactions with these blocks), and use client-to-server RemoteEvents to let the server know about interactions with the block (and ideally validate them).
How do i make it visible on certain players clients? I spawn the script for everyone and the lucky block part is visible and when u touch it it fires a remote event for the client. the thing is the local script doesn’t recognize that it has been fired because it doesn’t even know it has been cloned yet
You would send a RemoteEvent from server to only the players you want to see the block, using FireClient(). You could also use FireAllClients( listOfPlayers ) and have client code check LocalPlayer.UserId against the list of userIds you send with the remote. If it’s just 1 or 2 players, I’d go with the first option. If it should only be hidden to a small number of players, go with option 2 and send a list of players who should NOT see it.
You don’t need LocalScripts for this anymore. You can actually put 2 regular Script instances as children of the block itself, and set Script.RunContext to Server for the server-code, and Client for the client script. Unlike a LocalScript, a Script with RunContext Client will execute in the Workspace. The gotcha is that the scripts will also run anywhere, even from in ReplicatedStorage or ServerStorage, which is usually not what you want. You can either store the scripts with Enabled = false, and enable them when they are cloned and parented to the workspace, or you can do what I do and have a line at the top of the script like this:
if not script:FindFirstAncestorOfClass("Workspace") then return end
Which will just early-out if the script starts executing outside of the Workspace.
Ok I get how you can use 2 scripts but I need to have a local script due to render stepped only being on the client side. Render stepped is the only thing that works for me so far and I haven’t found any solutions or replacements from it as far as I know.
You can bind to RenderStepped from a Script that has RunContext of Client, just like from LocalScript. Generally you would only use RenderStepped if you need to position something in lockstep with the game camera. It’s the wrong event for most game code, just FYI, since it impacts framerate directly if used incorrectly to run non-camera code.
So what can I use if I don’t need to run camera code?
I’d recommend you watch some tutorials and look at the documentation. I highly recommend youtubers such as brawl dev etc. Learn the basics before coming to the forum and asking for help. Usually you can find answers to your questions already online with the right searches. If you can’t find an answer then maybe make a post on the forum.
Bro I found 5 posts on this topic none of them helped me and I read on the documentation that this was changed. Trust me out of my 4 years of coding I know what im doing I have been struggling on this for days and decided to make my own post. Youtube doesent really help me too. Thanks for the suggestion though
Why have the lucky block on the server. Just have a table with the information needed like its position and what type of lucky block it is. Then send an event to all clients to create a lucky block at that position. Simple replication, you don’t need to create anything on the server just store the data in a table. Let the client do all the visuals
You could create invisible and non-colliding lucky blocks on the server and tie them to a player list. Then tell the players on that list to make the block visible by using a RemoteEvent. And when a player touches the block, fire to the server from the client using a RemoteEvent. Finally verify that the client was on the list.
As @progamers246810 said, you could simply fire certain users with lucky block information, and then the client could clone a lucky block and use the given information to create a visual. And then when the user activates it, they tell the server.
very comprehensive solution and walkthrough