How do I make Client side scripts such that the script applies to the client, not the whole server?
Example Task (Give script based on this example)
I want a part to go invisible whenever a player touches it, it should go invisible only for the client from whom the player touched, nobody else should see it invisible unless they touch it too
Please give examples of how to use it if its in a part or block and how to use it if its in other places.
The following code will work when placed in a local script inside StarterGui
(or other client-only services), considering your game is FE (experimental mode off):
local part = -- Reference your part here local player = game.Players.LocalPlayer part.Touched:Connect(function(hit) if hit.Parent.Name == player.Name then part.Transparency = 1 end end)
Since your game is FE, the part turning transparent won't replicate to the server, therefor only the player who touched it will be able to see it turn invisible.
You could try this:
--Server script script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local RE = game.ReplicatedStorage.RemoteEvent RE:FireClient(game.Players:FindFirstChild(hit.Parent.Name,script.Parent) end end) --Client Script local RE = game.ReplicatedStorage.RemoteEvent RE.OnClientEvent:Connect(function(part) part.Transparency = 1 end)
(This is untested in studio)
Please reply if it works, or doesnt work :P
You would put this in a local script in the StarterPlayer --> StarterPlayerScripts
local part = Instance.new("Part") part.Parent = game.Workspace part.Name = "LocalPart" part.Position = Vector3.new(70.395, 7.619, 61.615) part.Size = Vector3.new(10.09, 10.8, 2) part.Anchored = true part.Touched:connect(function() part.CanCollide = false part.Transparency = .8 wait(2) part.CanCollide = true part.Transparency = 0 end)
Change the position, name and the size to be what you want, you can manipulate the part however you want as well. Such as changing the color, rotation, and material. I just did a simple part.