Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help me activate my position save script?

Asked by 4 years ago
Edited 4 years ago

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:

1game.Players.PlayerAdded:Connect(function(player)
2    local val = player:WaitForChild("Position")
3    player.CharacterAdded:connect(function(char)
4        while true do
5            wait(1)
6            val.Value = char:WaitForChild("HumanoidRootPart").Position
7        end
8    end)
9end)

Second script:

01local ds = game:GetService("DataStoreService")
02local ds1 = ds:GetDataStore("PositionSAvingSystem")
03 
04game.Players.PlayerAdded:Connect(function(player)
05    local val = Instance.new("Vector3Value",player)
06    val.Name = "Position"
07 
08    local userdata
09    pcall (function()
10        userdata = ds1:GetAsync(player.UserId)
11    end)
12 
13    if userdata then
14        game.Workspace:WaitForChild(player.name):WaitForChild("HumanoidRootPart").CFrame = CFrame.new(userdata.x, userdata.y, userdata.z)
15    else
View all 31 lines...
0
I don't know much about DataStores but you have a line of codes between `PlayerAdded` and `CharacterAdded`, because of that, the codes after that line won't work since `CharacterAdded` fires immediately once a character is added to the `Workspace`, try to move that code after `CharacterAdded` instead. NotTheChara 191 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

you would do that with a touch function like this

1local player  = game.Players.LocalPlayer
2local character = player.Character
3local Humanoid = character:WaitForChild("Humanoid")
4 
5YourPart.Touched:Connect(function(hit)
6    if hit.Parent:FindFirstChild("Humanoid") then --I edited this
7    --Code Here
8    end
9end)
0
it doesnt work Just_T0m 1 — 4y
0
is there any errors in the output? ShineBright2775 30 — 4y
0
Oh wait I think I did the "if" line wrong, I changed it though. It is supposed to be "if hit.Parent:FindFirstChild("Humanoid") not "if hit.Parent == Humanoid" ShineBright2775 30 — 4y
0
Truth is, thats only to check if it's touched by a player, if you want it to enable while being touched as a part, then jut remove the if and normally put your code. Frometa1998 35 — 4y
Ad

Answer this question