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

[Solved]Why is my comparison of player who is sitting and clicking on a brick not working?

Asked by 5 years ago
Edited by User#5423 5 years ago

This question has been solved by the original poster.

So i want the player sitting on the chair1 to be the only one that can click on the brick.. So that it changes another brick's materials and colors..

I tried outputting both the clicker name and the occupant of the seat... They both display the same result...However the comparison will not work, i.e the instructions within if Clicker.Name==occupied.Parent then

local x1       --the model that is supposed to change color & material

script.Parent.ClickDetector.MouseClick:Connect(function(Clicker)
    local occupied=game.Workspace.Chair1.Seat.Occupant

    if occupied==nil then
        --print("no one is sitting")
    else
        print(Clicker.Name)
        print(occupied.Parent)
        if Clicker.Name==occupied.Parent then
            print("WORKING???")
            x1=game.Workspace.x1:GetChildren()
            for i=1,3 do
                x1[i].Material="Neon"
                x1[i].BrickColor=BrickColor.new("Really red")   
            end
        end
    end

end)

EDIT : so i just realised occupied.parent is a userdata value

0
Okay..So i just had to convert the userdata value into string and it works mia290498 12 — 5y
0
A ClickDetector MouseClick passes the player character. You can also use https://developer.roblox.com/api-reference/function/Players/GetPlayerFromCharacter as occupied.Parent would be the char model. User#5423 17 — 5y

Answer this question