I’ve been currently delving into Remote Events and I’ve been struggling on how to make my code work.
What I am trying to aim for is to place parts in a loop from the server side while activating the loop and sending the mouse position from the client side. The problem is that the parts are not placing and I have been struggling for the past 3 hours.
Here are the scripts below:
CLIENT SIDE (LocalScript) ~~ In StarterPlayerScripts
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local mouse = player:GetMouse()
local mouseRemoteEvent = ReplicatedStorage:WaitForChild("MousePosition")
local checkRemoteEvent = ReplicatedStorage:WaitForChild("OnOrOff")
local thefalse = false
local mousePosition = nil
while thefalse and task.wait(0.1) do
mousePosition = mouse.Hit.Position
thefalse = thefalse
mouseRemoteEvent:FireServer(mousePosition)
checkRemoteEvent:FireServer(thefalse)
end
mouse.Button1Down:Connect(function()
thefalse = true
end)
mouse.Button1Up:Connect(function()
thefalse = false
checkRemoteEvent:FireServer(thefalse)
end)
SERVER SIDE (Script) ~~ In ServerScriptStorage
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local mouseRemoteEvent = ReplicatedStorage:WaitForChild("MousePosition")
local checkRemoteEvent = ReplicatedStorage:WaitForChild("OnOrOff")
local mousePosition = nil
local thefalse = false
while thefalse and task.wait(0.1) do
local part = Instance.new("Part")
part.Size = Vector3.new(10,10,10)
part.Shape = Enum.PartType.Cylinder
part.Anchored = false
part.Material = "Plastic"
part.BrickColor = BrickColor.new("Bright blue")
part.Position = mousePosition
part.Parent = workspace
task.delay(5, function() part:Destroy() end)
end
mouseRemoteEvent.OnServerEvent:Connect(function (receivedNumber)
mousePosition = receivedNumber
end)
checkRemoteEvent.OnServerEvent:Connect(function (receivedBoolean)
thefalse = receivedBoolean
end)
Anyone got any ideas to why the script isn’t working?