So, I want to create a system where a beam leads a player to a part only for the first time they ever play the game. So if they join again later, the beam will not lead them to the part. I have the beam working and it does go to the part, but the problem occurs when I put
local root = char:WaitForChild("HumanoidRootPart")
local a0 = root:WaitForChild("RootRigAttachment")
pathToPart(beam, a0, workspace:WaitForChild("Part"))
beam.Parent = char
between
if firstTime == true then
else
If I put it after the else, then it works fine. Apart from that, the other major problem is that it keeps happening every time you join. It only happens once, but it still occurs every time a player joins with the current code:
local datastore = game:GetService("DataStoreService"):GetDataStore("MyDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.CharacterAdded:Wait()
local firstTime = Instance.new("BoolValue")
firstTime.Parent = plr
firstTime.Name = "firstTime"
firstTime.Value = true
print(firstTime.Value)
local data
local success, errormessage = pcall(function()
data = datastore:GetAsync(plr.UserId)
end)
if success then
firstTime.Value = data
else
print("Error getting data")
warn(errormessage)
end
print(firstTime.Value)
local beam = script:WaitForChild("Beam"):Clone()
local function pathToPart(beam, a0, part)
local a1 = part:FindFirstChildOfClass("Attachment")
if a1 then
beam.Attachment0 = a0
beam.Attachment1 = a1
else
warn("No attachment was inserted into "..part:GetFullName())
end
end
if firstTime == true then
else
local root = char:WaitForChild("HumanoidRootPart")
local a0 = root:WaitForChild("RootRigAttachment")
pathToPart(beam, a0, workspace:WaitForChild("Part"))
beam.Parent = char
end
wait(1)
firstTime.Value = false
print(firstTime.Value)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
datastore:SetAsync(plr.UserId, plr.firstTime.Value)
end)
if success then
print("Saved")
else
warn(errormessage)
end
end)
If anyone could help, that would be awesome!
Thank you.