I made this thing where if the player clicks mouse button1, it spawns a part at the mouse location, it should only be spawning 1 part though, I cant work out why its doubling the amount of parts on every click.
Here is my code:
Client (local script in tool): β
wait(1)
local RS = game:GetService("ReplicatedStorage")
local Server = RS:WaitForChild("Server")
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UIS = game:GetService("UserInputService")
local Tool = script.Parent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character.HumanoidRootPart
Tool.Activated:Connect(function()
Mouse.Button1Down:Connect(function()
Server:FireServer(Mouse.Hit.Position)
print("sent to server")
end)
end)
Server code: (in tool) β
wait(1)
local RS = game:GetService("ReplicatedStorage")
local Server = RS:WaitForChild("Server")
local Replicate = RS:WaitForChild("Replicate")
Server.OnServerEvent:Connect(function(playerWhoFired, mouse)
print("got server")
Replicate:FireAllClients(playerWhoFired, mouse)
print("sent to bullet replication ")
end)
Local script in StarterPlayerScripts: β
wait(1)
local RS = game:GetService("ReplicatedStorage")
local Replicate = RS:WaitForChild("Replicate")
Replicate.OnClientEvent:Connect(function(playerWhoFired, mouse)
print("got replication")
local projectile = Instance.new("Part")
projectile.Parent = workspace
projectile.Position = mouse
end)
Any help is appreciated!