Hello, i made a script where when i touch a black part, i get the possibility to shoot blocks by clicking.
Almost everything works like i want but, the only problem is that when i touch that black part, everyone have the possibility to shoot blocks, not only me.
-- Local script
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local remote = game.ReplicatedStorage.RemoteEvent
local Part = game.Workspace:WaitForChild("PartToTouch")
local debounce = true
local touched = false
Part.Touched:Connect(function(plr)
if plr.Parent:FindFirstChild('Humanoid') then
touched = true
end
end)
mouse.Button1Down:Connect(function()
if touched == true then
if debounce == true then
debounce = false
remote:FireServer(mouse.Hit)
wait(0.5)
debounce = true
end
end
end)
--Server Script
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local Bloc = game.ReplicatedStorage.BlocTRW
RemoteEvent.OnServerEvent:Connect(function(plr, position)
print(position)
print(plr)
local clone = Bloc:Clone()
local character = plr.Character
clone.CanCollide = false
clone.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0,3,0)
clone.Parent = workspace
local direction = position.LookVector
local forceMultipliter = 300 * clone:GetMass()
clone:ApplyImpulse(direction * forceMultipliter)
wait(0.3)
clone.CanCollide = true
end)