I am trying to duplicate a room only on the client, and I already have that down.The issue is that the detector (which detects the play with part.Touched) calls twice, even though we have a variable that should stop that.
(Video of the issue)
robloxapp-20200626-1904282.wmv (950.7 KB)
Edit: Realised that I uploaded a download of the video, rather than embedding it. Is it possible to embed it instead as I understand people may not be comfortable with downloading anything?
out:
I have tried re-enabling the variable after to see if I was re-enabling to quickly, but that does not fix the issue. This is ran in a server script, and I am stuck on what to do to fix it. I imagine it is something stupid that I have done, but I do not know. It should also be noted that it is the touched event being called twice, not me calling the function by mistake.
Code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Modules = ReplicatedStorage:WaitForChild("Modules")
local GetDataServer = ServerStorage.Bindables.GetDataServer
local ChangeValue = ServerStorage.Bindables.ChangeValue
local ClientDuplication = Remotes:WaitForChild("ClientDuplication")
local ClientPropertyAssignment = Remotes:WaitForChild("ClientPropertyAssignment")
local DefaultData = require(Modules:WaitForChild("DefaultData"))
local part = script.Parent
local tpLocation = script.TPLocation.Value.Position
local defaultOffice = script.Target.Value
local clientDir = workspace.ClientRooms
local windowsTransparencyLevel = 0.8
local office = workspace.Office
local playerWindows = office.PlayerWindows
local canEnter = true
function PropertyWindows(player, dir)
for _, window in pairs(dir:GetChildren()) do
ClientPropertyAssignment:FireClient(player, window, "Transparency", windowsTransparencyLevel)
end
end
part.Touched:Connect(function(collider)
if not collider or not collider.Parent:FindFirstChild("Humanoid") or not canEnter then return end
canEnter = false;
print(collider.Name)
local character = collider.Parent
local localPlayer = Players:FindFirstChild(character.Name)
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not localPlayer or not humanoidRootPart then canEnter = true; return end
local hasOffice = GetDataServer:Invoke(localPlayer, DefaultData.ownerships.slot, "defaultOffice")
if not hasOffice then canEnter = true; return end
ChangeValue:Fire(localPlayer, DefaultData.primary.slot, "inHouseWith", localPlayer.UserId)
ClientDuplication:FireClient(localPlayer, defaultOffice, clientDir, tostring(localPlayer.UserId) .. defaultOffice.Name)
wait(1)
humanoidRootPart.Position = tpLocation
PropertyWindows(localPlayer, playerWindows)
for _, player in pairs(Players:GetPlayers()) do
if player.UserId == localPlayer.UserId then continue end
local inHouseWithPlayer = GetDataServer:Invoke(player, DefaultData.primary.slot, "inHouseWith") == localPlayer.UserId
if inHouseWithPlayer then continue end
for _, part in pairs(character:GetChildren()) do
if part:IsA("BasePart") then
ClientPropertyAssignment:FireClient(player, part, "Transparency", 1)
end
end
end
canEnter = true
end)