-
What do you want to achieve?
I want to enable my Tool.Activated function to pass 2 values from client to server on one activation, but to pass a different 2 values on the second activation, and require both activations for anything to occur. -
What is the issue?
Currently, when the player clicks with the tool equipped, the script waits for a second activation of the player clicking to fire a remote event to the server with the information of the first location of the mouse when the player clicked and the torso position of the player when they clicked, and when the player clicks a second time, the value of their new mouse position and torso position. Currently, when the player clicks once, and then twice, it works as expected, with the correct values being passed and the server responding correctly. However, after these first two activations, the client only fires the second activation portion of the local script! I am positive that there is some error or flaw in how I am waiting for the detection of two clicks in succession from the client-side.
I should also note that the server script has a sort of cool down, causing it to not produce any models (which is the function of it) until it has run the entire script, despite how much the client clicks.
Above pictures what happens the first time the player uses the tool by clicking twice in different locations (what is supposed to happen)
Above pictures a single click from the player, with the second mouse detection only being used, and the first mouse detection value remaining unchanged.
So my final question would be how would I keep the local script requiring two clicks from the player to fire to the server, and use the values in the correct order of activation (ex. the first model spawns where the first click is, and the second model spawns where the second click is)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("gargantaEvent")
local Tool = script.Parent
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local mouse = player:GetMouse()
local RunService = game:GetService("RunService")
Tool.Activated:Connect(function()
print("Click Detected")
local mousePosition = mouse.Hit.p
local torsoPosition = character.Torso.Position
repeat wait() until Tool.Activated:Connect(function()
print ("Click 2 Detected")
local mousePosition2 = mouse.Hit.p
local torsoPosition2 = character.Torso.Position
remoteEvent:FireServer(mousePosition, torsoPosition, mousePosition2, torsoPosition2)
end)
end)
Above is the local script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("gargantaEvent")
local TweenService = game:GetService("TweenService")
local clicked = false
local function onRemoteEvent(player, mousePosition, torsoPosition, mousePosition2, torsoPosition2)
if not clicked then
clicked = true
print "remote event detected on server"
local gargantaModelClone = game.ServerStorage.gargantaModel:Clone()
gargantaModelClone.Parent = game.Workspace
game.Workspace.gargantaModel:SetPrimaryPartCFrame(CFrame.new(mousePosition, torsoPosition) * CFrame.Angles(math.rad(-90), math.rad(0), math.rad(180)))
local gargantaModelClone2 = game.ServerStorage.gargantaModel2:Clone()
gargantaModelClone2.Parent = game.Workspace
game.Workspace.gargantaModel2:SetPrimaryPartCFrame(CFrame.new(mousePosition2, torsoPosition2) * CFrame.Angles(math.rad(-90), math.rad(0), math.rad(180)))
clicked = false
remoteEvent.OnServerEvent:Connect(onRemoteEvent)
Above is the relevant information from the server script