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

How do I make sure the player is on a specified brick when he clicks the button?

Asked by 6 years ago

I am trying to make a timer for an obby. I want the player to be at the start of the obby when he clicks the button on his screen to start the timer. I tried doing this with Touched and TouchEnded events but they don't work properly. I will idle on the starting brick and Roblox will say I'm not touching the brick when I am clearly touching the brick. The way the system is set up if Roblox says I'm not on the brick then I can't click the start timer button. Is there any way possible I could do what I want without using Touch and TouchEnded events because the are not reliable?

Client Code

--Loads event which will be needed to start the timer
local startTimerEvent = game.ReplicatedStorage.StartTimerEvent
local player = game.Players.LocalPlayer
--Starting place of the obby
local startBrick = game.Workspace.StartObby
--Is the player touching the brick?
local touchedStart = false

startBrick.Touched:Connect(function(hit)
    --Checks to make sure the one who is touching the brick is the same player
    --and not some other touching the brick
    if game.Players:GetPlayerFromCharacter(hit.Parent) == player then
        touchedStart = true
        print("Touched Began")
    end
end)

startBrick.TouchEnded:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) == player then
        touchedStart = false
        print("Touch Ended")
    end
end)

script.Parent.MouseButton1Click:Connect(function()
    if touchedStart then --If I am at the start then execute code
        print("Fired")
        --This next code tells the server to start the timer and stops the timer when
        --the player is dead.
        startTimerEvent:FireServer(player)
    end
end)

2 answers

Log in to vote
0
Answered by
Tomstah 401 Moderation Voter
6 years ago

The best idea might be to check the distance between the ClickDetector's parent and the user clicking on it. Another idea might be have a block below the player welded to him and use :GetTouchingParts() like said above. Another thing might be have a block on top of the block you want the player to be on that uses the same :GetTouchingParts(). All three of these should be viable methods.

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

There is a function called “GetTouchingParts()”, it makes a table and you could use for I, v in pairs, and do if v.Parent.Name == the players name then do whatever you want to do.

0
Sorry for lack of explanation, I’m on mobile so it’s cmgtotalyawesome 1418 — 6y
0
Very hard to type. ^ mobile cut me off mid sentence as an example... cmgtotalyawesome 1418 — 6y
0
I researched this function on the wiki and tested it in Studio and it said a part had to intersect but not touch. So no part of my player is in this list instead it says nil because there is nothing intersecting the start part. Is there anything else that I could do besides Touch and TouchEnded events and GetTouchingParts? Troloolooolooll 9 — 6y

Answer this question