I have these scripts here, and i want to activate them only by touching a part, so only if i touch a certain part the position saves. first script:
game.Players.PlayerAdded:Connect(function(player) local val = player:WaitForChild("Position") player.CharacterAdded:connect(function(char) while true do wait(1) val.Value = char:WaitForChild("HumanoidRootPart").Position end end) end)
Second script:
local ds = game:GetService("DataStoreService") local ds1 = ds:GetDataStore("PositionSAvingSystem") game.Players.PlayerAdded:Connect(function(player) local val = Instance.new("Vector3Value",player) val.Name = "Position" local userdata pcall (function() userdata = ds1:GetAsync(player.UserId) end) if userdata then game.Workspace:WaitForChild(player.name):WaitForChild("HumanoidRootPart").CFrame = CFrame.new(userdata.x, userdata.y, userdata.z) else ds1:SetAsync(player.UserId, { x= 0, y= 3, z= 0 }) end end) game.Players.PlayerRemoving:Connect(function(player) ds1:SetAsync(player.UserId, { x = player.Position.Value.x, y = player.Position.Value.y, z = player.Position.Value.z }) end)
you would do that with a touch function like this
local player = game.Players.LocalPlayer local character = player.Character local Humanoid = character:WaitForChild("Humanoid") YourPart.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then --I edited this --Code Here end end)