Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Key card in StarterPack?

Hi, I am trying to make a key card reader for my game, and I've got it to sort of work! If the keycard (tool) was in the same model as the rest of the gate, it would work. `

local TweenService = game:GetService("TweenService")
local door1 = script.Parent:WaitForChild("DelivGateLeft")
local door2 = script.Parent:WaitForChild("DelivGateRight")
local card = script.Parent:WaitForChild("Card")
local tweeningInformation = TweenInfo.new(
    7,   
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)

-- Tween information would go here
 
script.Parent.Detector1.Touched:Connect(function(hit)
	if hit.Parent == card then
    	tween1open:Play()
    	tween2open:Play()
    	wait(10)
    	tween1close:Play()
    	tween2close:Play()
	end
end)
				

So that is fine, but when I put the card into StarterPack, I cant seem to find anything that works! Do I have to change something at the top maybe?

2 answers

Hi, I think that you should check 'hit.Name' instead of checking if it's exactly the same object!

Example

script.Parent.Touched:Connect(function(hit)
	if hit.Name:lower():match("keycard") then
		-- script
	end
end)

1 comment

0

It still doesnt work! The detector1 is what I want the keycard to hit in order for the gate to open.

The card is not the part that hits it. The handle of the tool is, therefore you check for the handle.

script.Parent.Detector1.Touched:Connect(function(hit)
    if hit == card.Handle then
        tween1open:Play()
        tween2open:Play()
        wait(10)
        tween1close:Play()
        tween2close:Play()
    end
end)

2 comments

0

Ok, do I have to change something at the start too? (where it says local card)?

0

No it should work fine. If this is a local script try testing it in a normal script too.

This discussion is preserved as it was. New answers, comments, and votes are closed.