I have chests that open when a player clicks on the lid. When the player clicks on the lid it fires a RemoteEvent that are located inside the chests.
When I duplicated the chests and tested them, they both opened when I opened / clicked on ONE so I simply changed one of the lid's RemoteEvents to LidToggle2 and tried to see if only one would open after that and no.
Why is this happening and how do I fix this? I even edited the code inside to their corresponding RemoteEvent names and still both continue to open even though their RemoteEvent names are different.
The Code: The LocalScript that detects the click.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:connect(function() -- if the player chicks then ...
if script.Chest.Value and mouse.Target.Name == "Lock" and mouse.Target.Parent.Name == "Lid" then -- if they click the chests lock
script.Chest.Value.LidToggle2:FireServer() -- fire an event that the script will use
end
end)
The Code Pt.2
script.ChestLocalScript.Chest.Value = script.Parent -- setting a value
game.Players.PlayerAdded:connect(function(player) -- when a player is added
player.CharacterAdded:connect(function() -- and whenever their character is loaded then
if script.Parent.Configurations.StaticObject.Value == false then -- if this is not supposed to be a static object then
local newScript = script.ChestLocalScript:Clone() -- clone the local script
newScript.Parent = player.PlayerGui -- and put it in the player's playerGui
end
end)
end)
local hinge = script.Parent.Lid.HingePart -- making it easier to access this part
local lidOpen = false -- so we know if the chest is open or closed
local gold = game.ServerStorage.Gold:Clone()
if script.Parent.Configurations.StaticObject.Value == false then -- checking if this chest is supposed to open
hinge.BodyPosition.position = Vector3.new(hinge.Position.X,hinge.Position.Y,hinge.Position.Z)
hinge.BodyGyro.cframe = hinge.CFrame
for i, v in pairs(script.Parent.Lid:GetChildren()) do
v.Anchored = false
end
script.Parent.Lid.Lock.ClickDetector.MaxActivationDistance = 0
else
end
script.Parent.LidToggle2.OnServerEvent:connect(function() -- when an event is fired then see if we are to open or close the lid and set a value to do so
if lidOpen == false then
hinge.BodyGyro.cframe = hinge.BodyGyro.cframe * CFrame.Angles(0,0,math.rad(-90))
lidOpen = true
wait(3)
gold:Clone().Parent = game.Workspace
gold.Position = script.Parent.Lid.Lock.Position
wait()
script.Parent.Despawn.Disabled = true
wait(5)
hinge.BodyGyro.cframe = hinge.BodyGyro.cframe * CFrame.Angles(0,0,math.rad(90))
lidOpen = false
script.Parent.Despawn.Disabled = false
wait(1)
end
end)
Rest of the code located in a RegularScript.

1 comment
Code please?