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

Camera Position Changing For All Players?

Asked by
Rynappel 212 Moderation Voter
4 years ago

So i have a script and when you touch a block, it will fire an event and there is a local script in StarterGui and the local script will change the camera position of all players to like a shop thingy and this happens for all players and i only want it to happen to the player that touches the part, is there a way i can do that? Please help me lmoa

Server Sciript which is in the part which fires the remote event:

script.Parent.Touched:Connect(function()
    local event = game.ReplicatedStorage.Events:FindFirstChild("OpenVestShop")
    event:FireAllClients()
end)

Local Script in the StarterGui

game.ReplicatedStorage.Events.OpenVestShop.OnClientEvent:connect(function()
    local plr = game.Players.LocalPlayer
    local cam = workspace.CurrentCamera
    local char = plr.Character

    repeat wait()
        cam.CameraType = Enum.CameraType.Scriptable
    until cam.CameraType == Enum.CameraType.Scriptable
    cam.CFrame = workspace.LifeJacketShop.ShopCameras.ShopCam1.CFrame
end)

Please post an answer! Please anything will help me ;)

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago
--Your server script
--define variable "part" as the part which touches this thing
script.Parent.Touched:Connect(function(part)
    --Check if the part that touches this thing is in a model that is owned by a player.
    local plr = game.Players:GetPlayerFromCharacter(part.Parent)
    if plr then
        local event = game.ReplicatedStorage.Events:FindFirstChild("OpenVestShop")
        event:FireClient(plr)
    end
end)

Don't use :FireAllClients() as it's self-explanatory: it sends the request to every player that exist in the server. :FireClient(Player player) works best in this situation!

Also, isn't the title a little bit misleading...?

0
Thanks :DDDDD Rynappel 212 — 4y
0
Nice, worked for me too. Xapelize 2658 — 4y
Ad

Answer this question