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

My First place, second place/3rd place script isn't working properly?

Asked by 6 years ago
Edited 6 years ago

Title

ServerScript code (which I have no problem with if you need it here)

script.Parent.Touched:Connect(function(part)
    game.ReplicatedStorage.FirstPlaceEvent:FireAllClients(part)
end)

What happened is that when the remote event is triggered which I have no problem with the function being triggered but the wrong thing is that this script is not working properly...

game.ReplicatedStorage.FirstPlaceEvent.OnClientEvent:Connect(function(part)
    if part.Parent:FindFirstChild("Humanoid") then
        local player = game.Players[part.Parent.Name]
        local fpp = script.Parent.FirstPlacePlayer
        local spp = script.Parent.SecondPlacePlayer
        local tpp = script.Parent.ThirdPlacePlayer
        local stats = player.Place
        local firstPlace = stats.FirstPlace
        local secondPlace = stats.SecondPlace
        local thirdPlace = stats.ThirdPlace
        if  fpp.Text == "" and firstPlace == false and secondPlace == false and thirdPlace == false then
            firstPlace = true
            fpp.Text = player.Name
        elseif fpp.Text ~= "" and firstPlace == false and secondPlace == false and thirdPlace == false then
            secondPlace = true
            spp.Text = player.Name
        elseif fpp.Text ~= "" and spp.Text ~= "" then
            thirdPlace = true
            tpp.Text = player.Name
        else
            print(player.Name.."is neither first place, second or third")
        end
    end
end)

What happened is that it keeps saying in the output "mudathir2007 is neither first place, second or third" when I am really first to touch the brick... Please help if you do have a solution. Answers/comments are appreciated. And that's about all that what happened to this script.

Important Info:

Fire Type (FireServer, FireAllClients, FireClient): FireAllClients()

ServerScript Location:workspace.Part

Function Type (Touched, Changed, etc.) Touched

Security Mode: FilteringEnabled obviously

0
Shouldn't handle touched events locally. Also, what is "player" defined as? Touched events run multiple times if it touched another part. For example, if your brick was on top of your baseplate, the baseplate would register touched events. User#19524 175 — 6y
0
And OnClientEvent is localscript only, why are you using in server. User#19524 175 — 6y
0
Why not just check instead of the text value the `firstPlace` `secondPlace` and `thirdPlace` variables? You're being inconsistent. Also what's the text of `fpp`, `spp`, and `tpp` thebayou 441 — 6y
0
I'll add the serverscript code in the question mudathir2007 157 — 6y
View all comments (4 more)
0
ffp ssp ttp texts are "" (nothing) before being touched mudathir2007 157 — 6y
0
The problem may lie in your conditional statements (The "if ____ then" statements)  I think its the Stats.FirstPlace and stuff. If the value "firstPlace"  is a Bool Value, you may need to change the conditional statement for it. Try using "if firstPlace.Value == false then" ininja966 20 — 6y
0
incapaz I have no problem with the first parts of the script while ininja is right about the if then statements while it prints out I'm neither first second or third mudathir2007 157 — 6y
0
Okay i'll try hold on mudathir2007 157 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

The main problem could be your Conditional Statements. Starting with this line:

 if  fpp.Text == "" and firstPlace == false and secondPlace == false and thirdPlace == false then

I'm going to assume stats.firstPlace is a bool value unless stated otherwise The thing with bool values is that you need to do boolValue.Value to address if its true / false

So for example, try doing this instead

firstPlace.Value == false

If they are not BoolValues, I can see what else I can do to help. But I'm thinking the problem is the conditional statements because there is no errors.

Another note to mention, for some reason if you put a variable to equal BoolValue.Value and address it, it will not work (Or at least to my experience)

For example:

variable = BoolValue.Value

if variable == true then
    print"BoolValue is true"
end
0
I tried taht and it didn't work (yes it's a bool value) and if I change the 2nd place line it won't really be good because that allows more than 1 player to become 2nd place or 3rd and that's why I added if fpp.Text == "" mudathir2007 157 — 6y
0
wait you just reminded me of something in Line 1 mudathir2007 157 — 6y
Ad

Answer this question