So I am trying to make a viewport model appear when you touch a part which works fine however it’s all in a local script meaning it should be local for the player but it appears for everyone. Can someone help to see if I am doing something wrong.
The script
local ViewPortCamera = Instance.new("Camera",script)
ViewPortCamera.CameraType = Enum.CameraType.Scriptable
local db = false
local YIntager = .8
local XIntager = 2.5
local R = 0
local Item = game.Workspace.Celebrities.Temp
local ViewPortPoint = Vector3.new(0,0,0)
local player = game.Players.LocalPlayer
local ViewPortFrame = player.PlayerGui.ScreenGui:WaitForChild("ViewportFrame")
game:GetService("RunService").RenderStepped:Connect(function()
ViewPortFrame.LightDirection = Vector3.new(0,1,0)
ViewPortFrame.Ambient = Color3.fromRGB(255,255,255)
ViewPortFrame.CurrentCamera = ViewPortCamera
Item.PrimaryPart = Item.ItemPart
Item:SetPrimaryPartCFrame(CFrame.new(ViewPortPoint))
Item.Parent = ViewPortFrame
local cfrane, size = Item:GetBoundingBox()
local Max = math.max(size.X,size.Y,size.Z)
local distance = (Max/math.tan(math.rad(ViewPortCamera.FieldOfView))) * XIntager
local CurrentDistance = (Max/2) + distance
ViewPortCamera.CFrame = CFrame.Angles(0,math.rad(R),0) * CFrame.new(ViewPortPoint + Vector3.new(0,0,CurrentDistance),ViewPortPoint)
R = R +2
end)
-- Detect what part is being touched
for i,v in ipairs(game.Workspace.CelebParts:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function()
if not db then
db = true
Item = game.Workspace.Celebrities:FindFirstChild(v.Name):Clone()
script.Parent.ViewportFrame.Visible = true
wait(5)
db = false
script.Parent.ViewportFrame.Visible = false
script.Parent.ViewportFrame:FindFirstChild(v.Name):Destroy()
end
end)
end
end
If anyone can help me work out why this is displaying for everyone, that would be grand.