I’m trying to make the “Star” client sided. I’ve tried some things but I still don’t get how?
One of the things that I’ve tried is to place the Star in Workspace from Replicated Storage for clients, but then the script doesn’t work and the star then does absolutely nothing.
By making the Star/Stars client-sided I mean that when I touch it I get it and the star disappears for me, but for other clients who have not touched it, the star/stars are still there for them.
Video:
Script:
--// Main
script.Parent.Parent.Main.Touched:connect(function(hit) --> When hit do the Star Magic.
if hit.Parent:FindFirstChild("Humanoid") and Cooldown == false then
Cooldown = true --> Enables cooldown on Hit.
local Humanoid = hit.Parent.Humanoid
Humanoid.WalkSpeed = 0 --> Disables walking.
Humanoid.JumpPower = 0 --> Disables jumping.
local AnimTrack = hit.Parent.Humanoid:LoadAnimation(Animation) --> Loads animation.
AnimTrack:Play() --> Plays animation.
PlaySound() --> Creates sound and plays it.
local Player = game.Players:GetPlayerFromCharacter(hit.Parent) --> Get's player.
game.ReplicatedStorage.Events.TriggerCamera:FireClient(Player) --> Fires camera Event.
StarCollected() --> Does the Star collected trick.
local Data = Player:FindFirstChild("Data") --> Finds player's data.
Data.Stars.Collected.Value = Data.Stars.Collected.Value + 1 --> Rewards 1+ star.
wait(CooldownTime)
Cooldown = false
Humanoid.WalkSpeed = 16 --> Enables walking.
Humanoid.JumpPower = 50 --> Enables jumping.
DestroyStar() --> Destroys the star.
wait(RemoveSoundTime) --> Waits "Time"
RemoveSound() --> Removes the sound.
end
end)
You could consider placing the star inside the user’s CurrentCamera. Of course, this will require a local script in order for objects to be placed inside the CurrentCamera. Example:
What Player1 sees:
–server wants to spawn a coin / star for all players
server → send remote event call to all clients
clients → receive the server call and spawn the star within their own local environment
–touched event
client → if star is touched, then destroy it, and then tell the server via remote event call
server → receive call from particular client, and update the player’s data
It’s nice having the interaction implementation on the client-side, so that players can’t sense latency within the game.
You could use Part.LocalTransparencyModifier to make the part transparent only on the client, which is probably what you need.
You could also clone the star on the client and make the server’s star invisible with LocalTransparencyModifier, then the client can do whatever they want with the star they cloned, which includes making it do everything that the server’s star is doing.
Disclaimer: You can just use Part.Transparency on the client to achieve the same effect using FilteringEnabled
So LocalTransparencyModifier is great and all, but you also have to keep track of it and set the value every frame. Not the best solution here where there will most likely be a lot of stars meaning a lot of extra work for the renderstepped loop to handle.
But if you create the star on the server and basically put the script you provided into a local script it will have the desired effect of only one person seeing it go invisible.
I did what you said and it doesn’t work, but if I rewrite the Touched part in the script so it’s local in the script and so it gets the local player then I doubt that it should would work.
I’ve actually asked about making a part client sided (kinda) hopefully this can help translate with what you’re needing to do?
Basically, making the touched event local instead of server sided.
Then putting in the characterscripts folder.
Theeeeen, detecting if it hits “Star” then doing the script so on.
Edit: Use a local script instead and detect the parts named “Star” and using a local touched event as normal. Kinda like collection service, heard you can do that too.
Edit: Dun did do it lol
(Many errors tho and its very messy but basically just use a local touchedevent. Also, don’t use what I used since its very bad but gives you an idea I guess?) StarsClientSideFixedKinda.rbxl (54.2 KB)
I’m sure you can destroy something on the client without destroying it on the server via a local script. That way it still exists for everyone who hasn’t touched it yet. You just need to use a remote event to tell the client to destroy it.
I also fixed it, made literally all the script client-sided and also used CollectionService to copy all star scripts into the stars from a LocalController in ReplicatedStorage.
I also changed the event in ReplicatedStorage to a bindable instead of a remote since it’s all on the same side of the client-server model.
User @Rocky28447’s method, he cleaned it up even more.
I did nearly the same thing. Used CollectionService to tag all the stars and just iterate through them on load, setting up the touched events. Added in an extra script in ServerScriptService to deal with the incrementing of the star count as well. Fixed all indenting too.
Any changes made by a LocalScript will only show for the client it runs on. It doesn’t matter if the object you are interacting with was created locally or not (of course that is a local change), or where it was placed. If you want the server to still have access to the same object you don’t want to create it locally. As long as you use a LocalScript you shouldn’t have any issues. If you need to communicate between the server and client you can use Remotes.