Remote event needs client script, but tweening needs server script?

Hello!

I am making a game with roleplaying stuff; one part is an alarm system. I decided I wanted it also to open the doors as well as flashing lights. I’ve tested the alarm system and it works fine. It supposedly fires on all clients. The problem I have is the doors. It is my understanding that the server handles block positions, not the client, but the client is the only one able to receive the OnClientEvent:Connect function with a client script. How am I supposed to affect things in the server if I can only use a client script to connect?

I either receive an
attempt to index nil with 'position'
or an
Onclientevent can only be used on the client

Thanks!

What data are you trying to send with position and how do you receive the data?

2 Likes

I’m trying to index the initial position of the parts before they are tweened.
The line it’s whining about is local initialPosition1a = part1a.Position

1 Like

It’s really not that easy to work little to no information, could you provide some code snippets on how you are trying to achieve what you want to make

1 Like

Im not exactly sure what data you’re asking for.

This is where I define the parts and the vectors
local doorModel1 = script.Parent.Part1
local doorModel2 = script.Parent.Part2

local part1a = doorModel1:FindFirstChild("A")
local part1b = doorModel1:FindFirstChild("B")
local part1c = doorModel1:FindFirstChild("C")

local part2a = doorModel2:FindFirstChild("A")
local part2b = doorModel2:FindFirstChild("B")
local part2c = doorModel2:FindFirstChild("C")

local initialPosition1a = part1a.Position
local initialPosition1b = part1b.Position
local initialPosition1c = part1c.Position

local initialPosition2a = part2a.Position
local initialPosition2b = part2b.Position
local initialPosition2c = part2c.Position

local openOffset1 = Vector3.new(4, 0, 0) -- Change these offsets as needed
local openOffset2 = Vector3.new(-4, 0, 0) -- Change these offsets as needed
...
local doorOpen = script:FindFirstChild("Value")
...
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut)
This the relevant part of the door closing and opening function
local function toggleDoor()
	-- Check if the button is on cooldown
	if isOnCooldown then
		return
	end
...

	if doorOpen.Value == true then
		doorOpen.Value = false
		
		local part1aTween1 = game:GetService("TweenService"):Create(part1a, tweenInfo, {Position = initialPosition1a})
		local part1bTween1 = game:GetService("TweenService"):Create(part1b, tweenInfo, {Position = initialPosition1b})
		local part1cTween1 = game:GetService("TweenService"):Create(part1c, tweenInfo, {Position = initialPosition1c})

		local part2aTween1 = game:GetService("TweenService"):Create(part2a, tweenInfo, {Position = initialPosition2a})
		local part2bTween1 = game:GetService("TweenService"):Create(part2b, tweenInfo, {Position = initialPosition2b})
		local part2cTween1 = game:GetService("TweenService"):Create(part2c, tweenInfo, {Position = initialPosition2c})
		

		part1aTween1:Play()
		part1bTween1:Play()
		part1cTween1:Play()

		part2aTween1:Play()
		part2bTween1:Play()
		part2cTween1:Play()

	else 

		doorOpen.Value = true

		local part1aTween2 = game:GetService("TweenService"):Create(part1a, tweenInfo, {Position = initialPosition1a + openOffset1})
		local part1bTween2 = game:GetService("TweenService"):Create(part1b, tweenInfo, {Position = initialPosition1b + openOffset1})
		local part1cTween2 = game:GetService("TweenService"):Create(part1c, tweenInfo, {Position = initialPosition1c + openOffset1})

		local part2aTween2 = game:GetService("TweenService"):Create(part2a, tweenInfo, {Position = initialPosition2a + openOffset2})
		local part2bTween2 = game:GetService("TweenService"):Create(part2b, tweenInfo, {Position = initialPosition2b + openOffset2})
		local part2cTween2 = game:GetService("TweenService"):Create(part2c, tweenInfo, {Position = initialPosition2c + openOffset2})
		part1aTween2:Play()
		part1bTween2:Play()
		part1cTween2:Play()

		part2aTween2:Play()
		part2bTween2:Play()
		part2cTween2:Play()

...
			end
		end)
	end
Then this function waits for the event to be fired
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MusterAlarmEvent = ReplicatedStorage:WaitForChild("MusterAlarmEvent")

local function onMusterAlarm()
	toggleDoor()
end

MusterAlarmEvent.OnClientEvent:Connect(onMusterAlarm)

Please let me know if you need other data. As I said earlier, the event fires correctly and connects.

Make sure that the Script that is getting the remote fire is a Local Script, not a Server Script

1 Like

That’s the problem. If it’s a local script, it can’t change the position of the parts

1 Like