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

This key script will work in test mode but not when you actually play the game. Anyone know why?

Asked by 7 years ago

This key script is a local script which is placed in replicated first. It works perfectly in test mode but when you actually join it doesn't work. Anybody know why and how to fix it?

game.workspace.BDoor1.Touched:connect(function(hit)
    if hit.parent.name == "Key" and hit.Parent.ClassName == "Tool" then
       game.workspace.BDoor1.Transparency = 1
       game.workspace.BDoor1.CanCollide = false
    end
end)

2 answers

Log in to vote
2
Answered by
Asceylos 562 Moderation Voter
7 years ago
game.Workspace.BDoor1.Touched:connect(function(hit)
    if hit.Parent.Name == "Key" and hit.Parent:IsA("Tool") then
       game.Workspace.BDoor1.Transparency = 1
       game.Workspace.BDoor1.CanCollide = false
    end
end)

With correct capitalization and little changes.

0
Damn, you just barely got there first haha. Upvoted. aztec_glory 63 — 7y
0
haha Asceylos 562 — 7y
Ad
Log in to vote
1
Answered by 7 years ago

Your first issue is that the local script's parent is ReplicatedFirst. Try making it a script and placing this in the ServerScriptService -

game.Workspace.BDoor1.Touched:Connect(function(hit)
    if hit.Parent.Name == "Key" and hit.Parent:IsA("Tool") then
       game.Workspace.BDoor1.Transparency = 1
       game.Workspace.BDoor1.CanCollide = false
    end
end)

Don't forget to accept an answer! :)

Answer this question