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

How do I get a value in a model?

Asked by 7 years ago
a=script.Parent.Parent.Door
function onTouch(hit)
    print(hit)
    if hit.Parent.IntValue.Value==2  then a.Transparency=1
        script.Parent.BrickColor=BrickColor.new("Lime green")
        a.CanCollide=false
        wait(3)
        a.Transparency=0.6
        a.CanCollide=true
        script.Parent.BrickColor=BrickColor.new("Really red")
    end
end

script.Parent.Touched:connect(onTouch)

So basically the point of this creation is to get the tool, and if the tool has an IntValue inside of it with a value of 2, the door is supposed to open. However it just sends a message back saying IntValue is not a valid member of model, I even tried using simply just Value. Please help?

0
You have to actually index the tool. 'hit.Parent' is the potential Character. Goulstem 8144 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Alright, lots of what's happening here is wrong lol.

local Door =script.Parent.Parent.Door -- Don't use single letters, and USE LOCAL
function onTouch(hit)
    print("hit") -- It's just for testing reasons, right?
    if hit.Parent:FindFirstChild("IntValue") ~= nil then -- Will return nil if there's no Value
    if hit.Parent.IntValue.Value~=2  then return end 
    Door.Transparency=1
        script.Parent.BrickColor=BrickColor.new("Lime green")
        Door.CanCollide=false
        wait(3)
        Door.Transparency=0.6
        Door.CanCollide=true
        script.Parent.BrickColor=BrickColor.new("Really red")
    end
end

script.Parent.Touched:Connect(onTouch) --Make sure :Connect is in caps

Ad

Answer this question