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

How can I change a boolvalue inside a player on touch of an object? Also change games?

Asked by 4 years ago
Edited 4 years ago

So what I have is I want to change a boolvalue in a player, I've made a script to put value in the player and this is that script.

game.Players.PlayerAdded:Connect(function(player)
    local boolValue = Instance.new("BoolValue", player)
    boolValue.Name = "InPod"
    boolValue.Value = false
end)

Then of course it appears in the player but I cant for the life of it change the value I have this script but I can't get it to work!


function onTouched(part) local v = part.Parent:findFirstChild("InPod") if v ~= false then v.Value = true end end script.Parent.Touched:connect(onTouched)

Also I'm pretty new to scripting and this is my first proper game so please put into detail thanks :).

EDIT: I thought I forgot something when the value is true it should not teleport the player to another game which I need and when the value is false, it should teleport the player to a different game, also heres what I have thanks to help by botw_legend I have this.

script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then
        local bool = part.Parent.InPod
        bool.Value = true
    end
end)
game.Players.PlayerAdded:Connect(function(plr)
    local char = game.Workspace:WaitForChild(plr.Name)
    local bool = Instance.new("BoolValue",char)
    bool.Name = "InPod"
    bool.Value = false
end)
0
i commented on ur question v down there just letting u know cause you don't get a notification if i comment on my question botw_legend 502 — 4y
0
ok i updated my answer tell me if it doesn't work botw_legend 502 — 4y
0
ok i updated my answer tell me if it doesn't work botw_legend 502 — 4y
0
i updated my answer can u tell me if it doesn't work? botw_legend 502 — 4y
View all comments (5 more)
0
i added a comment botw_legend 502 — 4y
0
i added a comment botw_legend 502 — 4y
0
ok changed my answer botw_legend 502 — 4y
0
i added a comment botw_legend 502 — 4y
0
ahh ok i made a change to my code i think i fixed it for good this time, hope it works! botw_legend 502 — 4y

1 answer

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

so i tested this and it works so in the part you want it to touch add a script and put in this code:

local TeleportService = game:GetService("TeleportService")
script.Parent.Touched:Connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") and part.Parent:FindFirstChild("InPod") then
        local player = game.Players:FindFirstChild(part.Parent.Name)
        local bool = part.Parent.InPod
                bool.Value = true
        TeleportService:Teleport(numbers, player)--change numbers
    end
end)
game.Players.PlayerAdded:Connect(function(plr)
    local char = game.Workspace:WaitForChild(plr.Name)
    local bool = Instance.new("BoolValue",char)
    bool.Name = "InPod"
    bool.Value = false
end)

placeid is the number in the link when viewing your game a picture would look like this

it will put in a bool in the character and if you step or touch the part it will turn it from false to true i hope this helped!

0
Thank you! I've started and I thought I forgot something, I need it to teleport to a game too, basically the idea I have is when the value is true, it wont teleport the player, but when the value is false it will teleport the player to another game. how could it be intagrated into the script? Thanks for the help. jaydenrobloxreviewer 9 — 4y
0
i can do that but i have a question so do you want it to teleport the player if they step on it? or do you need to do more that that because you can do that without having a bool in the player botw_legend 502 — 4y
0
Basically after a certain amount of time I've stepped on the brick that makes boolvalue true id have one my scripts check if the value is false and continue doing something else that I've set it to. But it the value is true, it would teleport the player to another game. jaydenrobloxreviewer 9 — 4y
0
Ok getting closer this time I think but now theres 4 "InPod" BoolValues in my character and in console it just says "Invalid player to teleport" heres a video of it: https://www.dropbox.com/s/1h0k2du69fztl7v/2020-07-30%2013-20-45.mp4?dl=0 jaydenrobloxreviewer 9 — 4y
View all comments (21 more)
0
Correction fixed the boolvalue issue I just have Invalid player to teleport jaydenrobloxreviewer 9 — 4y
0
Ok now I added that line and I'm now using a local script but now the value is not being added and there is no error in cosole and its not teleporting me? jaydenrobloxreviewer 9 — 4y
0
Also sorry for the late response took a break from PC for a bit and forgot. jaydenrobloxreviewer 9 — 4y
0
ok can you put a print statment in between lines 4 and 5 and tell me if they run? botw_legend 502 — 4y
0
Ok is this right? https://imgur.com/1L4OQdY If it is its not printing anything in my console jaydenrobloxreviewer 9 — 4y
0
Also the word player has an orange underline for some reason. jaydenrobloxreviewer 9 — 4y
0
ok now can you add a print statment between lines 1 and 2 and tell me if they print botw_legend 502 — 4y
0
It's not putting anything in the console still, the script is Enabled and that so I don't know? jaydenrobloxreviewer 9 — 4y
0
when you did that did you step on the part? because the line is suppost to only run when you step on the part botw_legend 502 — 4y
0
Not long after joining the game. When I touch the part it does nothing here's a better recording https://www.dropbox.com/s/w66rfdgk3ptqstm/2020-08-05%2022-20-38.mkv?dl=0 jaydenrobloxreviewer 9 — 4y
0
i tested it, it does work is the script a regular script not local and the parent is the part? botw_legend 502 — 4y
0
It's a local script I'll make it just a regular one again, and I'm not so sure? Just basically the player gets detected and the boolvalue is true, it will teleport the player. jaydenrobloxreviewer 9 — 4y
0
Ok now the boolvalue is showing up and being set to true. but the console is still saying Invalid Player to Teleport and saying the print stuff here's a link: https://imgur.com/a/kMvTYF3 jaydenrobloxreviewer 9 — 4y
0
I'm now getting and error saying "Line 6 Teleport" something like that. jaydenrobloxreviewer 9 — 4y
0
so view the front page of your game then click the 3 dots next to the title then hit configure this game then go to places then click on the place where you want the player to be teleported to then in the link, there are lots of numbers click on the lots of numbers and copy them and paste them to the line 6 where there are lots of numbers botw_legend 502 — 4y
0
I've done that it's just saying: Workspace.Pod.Part.Script:6: attempt to index nil with 'Teleport' and the script is: https://imgur.com/a/QukOcQ3 jaydenrobloxreviewer 9 — 4y
0
OHHH ok so what you need to do is take this line local TeleportService = game:GetService("TeleportService") and paste it in the very top line botw_legend 502 — 4y
0
Getting" Invalid player to teleport" again. jaydenrobloxreviewer 9 — 4y
0
really? awww botw_legend 502 — 4y
0
Yay! It works! Thank you so much. jaydenrobloxreviewer 9 — 4y
0
your welcome! Glad i could help! botw_legend 502 — 4y
Ad

Answer this question