I’m trying to make a system where if a player flys high enough they hit a transparent part with CanCollide off, then when they hit that part it hides the baseplate and makes the earth model visible, then when they fly into the earth model, it makes the baseplate visible again and hides the earth model. Now it’s partially working, when I fly and hit the part it hides the baseplate and makes the earth visible, however then it gives me an error.
I have this script in ServerScriptService to create value in the player.
--//Services
--//Instances
--//Data
--//Functions
--//Events
--//Script
game.Players.PlayerAdded:Connect(function(plr)
local Values = Instance.new("Folder", plr)
Values.Name = "Values"
local Location = Instance.new("StringValue", Values)
Location.Name = "Location"
Location.Value = "Earth"
end)
I also have this script in ServerScriptService to detect when one of the objects are touched.
--//Services
local RepStorage = game:GetService("ReplicatedStorage")
--//Instances
local Model = workspace.LeaveEarth
local Events = RepStorage:WaitForChild("Events")
local EarthEvent = Events.Planets:WaitForChild("Earth")
local Earth = RepStorage.Planets:WaitForChild("Earth")
--//Data
local db = false
local cd = 4
--//Functions
--//Events
--//Script
--Earth--
for _,LeaveEarth in ipairs(Model:GetDescendants()) do
if LeaveEarth:IsA("Part") then
LeaveEarth.Touched:Connect(function(hit)
if not db then
db = true
local HitPart = hit.Parent
print("Touched!")
if HitPart:FindFirstChildWhichIsA("Humanoid") then
print("Is Human")
local Character = HitPart
local Player = game.Players:GetPlayerFromCharacter(Character)
local Values = Player:WaitForChild("Values")
local Location = Values.Location
EarthEvent:FireClient(Player, Location)
wait(cd)
db = false
end
end
end)
end
end
for _,EnterEarth in ipairs(Earth:GetDescendants()) do
if EnterEarth:IsA("MeshPart") then
EnterEarth.Touched:Connect(function(hit)
if not db then
db = true
local HitPart = hit.Parent
print("Touched!")
if HitPart:FindFirstChildWhichisA("Humanoid") then
print("Is Human")
local Character = HitPart
local Player = game.Players:GetPlayerFromCharacter(Character)
local Values = Player:WaitForChild("Values")
local Location = Values.Location
EarthEvent:FireClient(Player, Location)
wait(cd)
db = false
end
end
end)
end
end
--Value Changing
EarthEvent.OnServerEvent:Connect(function(Location, Place)
Location.Value = Place
end)
Then I have this script in StarterCharacterScripts to make the planet invisible/visible.
--//Services
local RepStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")
--//Instances
local Events = RepStorage:WaitForChild("Events")
local EarthFloor = workspace:WaitForChild("Baseplate")
local EarthDetector = workspace:WaitForChild('LeaveEarth')
local Planets = RepStorage:WaitForChild("Planets")
local Detectors = Planets:WaitForChild("Detectors")
local Skys = RepStorage:WaitForChild("Skys")
local SpaceSky = Skys:WaitForChild("SpaceSky")
local EarthSky = Lighting:WaitForChild("EarthSky")
local EarthModel = Planets:WaitForChild("Earth")
--//Data
--//Functions
function Earth(Location, EarthEvent)
if Location.Value == "Earth" then
local Place = "Space"
EarthEvent:FireServer(Location, Place)
SpaceSky.Parent = Lighting
EarthSky.Parent = Skys
EarthModel.Parent = workspace
EarthFloor.Parent = Planets
EarthDetector.Parent = Detectors
elseif Location.Value == "Space" then
local Place = "Earth"
EarthEvent:FireServer(Location, Place)
SpaceSky.Parent = Skys
EarthSky.Parent = Lighting
EarthModel.Parent = Planets
EarthFloor.Parent = workspace
EarthDetector.Parent = workspace
end
end
--//Events
local EarthEvent = Events.Planets:WaitForChild("Earth")
--//Script
EarthEvent.OnClientEvent:Connect(function(Location)
Earth(Location, EarthEvent)
end)
However it gives me this error in the hit detection script
19:00:17.978 Value is not a valid member of Player "Players.FadedOrder" - Server - New:67
This is the line thats erroring,
Location.Value = Place
Any help would really be appreciated.