In short terms - im making a game which has an interaction system.
The problem is when i tried making an additional check if it’s occupied the script is working by a single scenario - Getting me an empty value in ‘Occypiedby’ attribute.
Can you guys help me?
Any help is appreciated
Following examples of code are getting me error
1st piece of code on client
-- local function MakeCoroutine()
return coroutine.create(function()
print(EstimatedTime)
while UserInputService:IsKeyDown(Enum.KeyCode.F) do
if Interacting == true then
if wastedtime >= EstimatedTime and Interacting == true then
Inter:FireServer(target.Instance, "Done")
print("Fired")
target = nil
wastedtime = 0
break
elseif looking == false or tostring(target.Instance.Parent.Setup:GetAttribute("Occupiedby")) ~= tostring(plr.UserId) then
print('wrongid')
print(plr.UserId)
print(target.Instance.Parent.Setup.Occupiedby.Value)
wastedtime = 0
target = nil
break
elseif wastedtime <= EstimatedTime and Interacting == true and looking == true then
wait(0.25)
wastedtime += 0.25
print(wastedtime)
else
print(plr.UserId, " else")
print(target.Instance.Parent.Setup:GetAttribute("Occupiedby"))
target = nil
wastedtime = 0
break
end
end
end
end)
end
local KeyHold = MakeCoroutine()
UserInputService.InputBegan:Connect(function(InputObject, gameProcessedEvent)
if gameProcessedEvent then return end
if InputObject.KeyCode == Enum.KeyCode.F and CanInteract == true then
if target and target.Instance.Parent.Name ~= "Interacted" then
Inter:FireServer(target.Instance, "Starting")
CanInteract = false
Interacting = true
Info = TweenInfo.new(EstimatedTime, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
Tween = TS:Create(Progressbar, Info, {Size = UDim2.new(1, 0, 1, 0)})
UserInputService.MouseDeltaSensitivity = 0
AbleToRun.Value = false
coroutine.resume(KeyHold)
Tween:Play()
Tween.Completed:Connect(function()
hide()
UserInputService.MouseDeltaSensitivity = BaseOfSensitivity[1]
end)
end
end
end)
2nd piece of code which is on server side
Inter.OnServerEvent:Connect(function(Player, target, state)
task.spawn(function()
print(target)
if target and state == "Starting" then
target.Parent.Setup:SetAttribute("Occupiedby", tostring(Player.UserId))
print(target.Parent.Setup:GetAttribute("Occupiedby"))
end
if target and state == "Done" then
target.Parent.Setup:SetAttribute("Occupiedby", '')
end
if target and state == "Stopped" then
target.Parent.Setup:SetAttribute("Occupiedby", '')
end
-- Checking part started --
if target.Parent:HasTag("Door") and state == "Done" then
OpenDoor(target.Parent, 90)
end
-- Checking part ended --
if target.Parent:HasTag("Multi") then
target.Parent.Name = target.Parent.Name
else
target.Parent.Name = "Interacted"
end
end)
end)