Hi, so I want to make it so that when a part is touched, a cutscene will trigger but I only want the player to see the cutscene once. So I wanted to use a datastore to save a variable that is either 0 (have not touched) or 1 (has touched) and when the player touches the part, it changes the variable to 1 and moves the part so it cannot be touched again. I already have the scripts for the cutscene working, but for some reason, the variable won't save and the part won't move. This is my first time-saving variables in datastore so I don't know what I did wrong :c

local DS = game:GetService("DataStoreService")
local DidCutSceneTrigger1 = DS:GetDataStore("CutTrigOne")
local debounce = 0


game.Workspace.CutTrig1.Touched:Connect(function(hit)
  local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
  if plr and debounce == 0 then
        debounce = 1
        game.Workspace.CutTrig1.Position = Vector3.new(-111.5, 38.086, -5.7)
  end
end)

game.Players.PlayerAdded:Connect(function(player)
  local success, errormessage = pcall(function()
    data = DidCutSceneTrigger1:GetAsync(player.UserId .. "-didSee")
  end)  
  if success then
      debounce = data
  end
end)

game.Players.PlayerRemoving:Connect(function(player)
  local success, err = pcall(function()
    DidCutSceneTrigger1:SetAsync(player.UserId.. "-didSee", debounce)
  end)
end)

if debounce == 1 then
    game.Workspace.CutTrig1.Position = Vector3.new(-111.5, 38.086, -5.7)
else
    game.Workspace.CutTrig1.Position = Vector3.new(-111.5,12.33,-5.7)
end

I didn't get any errors ;-;

3 comments

0

Try printing the data you get.

0

Are you doing it in Studio?

0

Yes