-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCloud.lua
More file actions
95 lines (79 loc) · 2.49 KB
/
Cloud.lua
File metadata and controls
95 lines (79 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
-- Local Cloud Stand Script (Thin Platform, Correct Height)
-- Put this LocalScript in StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
-- Folder for local collision platforms
local cloudFolder = Instance.new("Folder")
cloudFolder.Name = "LocalCloudPlatforms"
cloudFolder.Parent = Workspace
-- Settings
local transparency = 1 -- 1 = invisible, 0 = visible
local platformPrefix = "LocalCloudPlatform__"
local platformThickness = 1 -- how thick the collision sheet is
-- Store cloud-to-platform pairs
local cloudPlatforms = {}
-- Check if a part looks like a cloud
local function isCloudPart(part)
if not part:IsA("BasePart") then
return false
end
local name = string.lower(part.Name)
return string.find(name, "cloud") ~= nil
end
-- Create platform on top of cloud
local function createPlatform(cloudPart)
if cloudPlatforms[cloudPart] then
return
end
local platform = Instance.new("Part")
platform.Name = platformPrefix .. cloudPart:GetDebugId()
platform.Anchored = true
platform.CanCollide = true
platform.Transparency = transparency
platform.CastShadow = false
platform.Parent = cloudFolder
cloudPlatforms[cloudPart] = platform
end
-- Remove platform when cloud is gone
local function removePlatform(cloudPart)
local platform = cloudPlatforms[cloudPart]
if platform then
platform:Destroy()
cloudPlatforms[cloudPart] = nil
end
end
-- Update all platforms in one loop
RunService.RenderStepped:Connect(function()
for cloudPart, platform in pairs(cloudPlatforms) do
if not cloudPart or not cloudPart.Parent then
removePlatform(cloudPart)
else
-- Match cloud X/Z size, but make Y very thin
platform.Size = Vector3.new(cloudPart.Size.X, platformThickness, cloudPart.Size.Z)
-- Place exactly on top surface of the cloud
local offsetY = (cloudPart.Size.Y / 2) + (platform.Size.Y / 2)
platform.CFrame = cloudPart.CFrame * CFrame.new(0, offsetY, 0)
end
end
end)
-- Initial scan
for _, obj in Workspace:GetDescendants() do
if isCloudPart(obj) then
createPlatform(obj)
end
end
-- Watch for new clouds
Workspace.DescendantAdded:Connect(function(desc)
if isCloudPart(desc) then
createPlatform(desc)
end
end)
-- Cleanup when clouds are removed
Workspace.DescendantRemoving:Connect(function(desc)
if cloudPlatforms[desc] then
removePlatform(desc)
end
end)
print("[LocalCloudStand] You can now stand perfectly on top of clouds!")