Hello! I was wondering how I should go about making my tower placement system non-exploitable. It is currently all local making it very vulnerable. Here is the script:
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local PlayerGui = player:WaitForChild('PlayerGui')
local Gui = PlayerGui:WaitForChild('ScreenGui')
local SpawnButton = Gui:WaitForChild('TextButton')
local IsSpawning = false
local CanPlace = false
local CurrentDecoy = nil
local Rotation = 1
--//Create Decoy\\--
function CreateDecoy()
local Towers = game:GetService('ReplicatedStorage'):WaitForChild('Towers')
local GunnerUpgrades = Towers:WaitForChild('GunnerUpgrades')
local TowerDecoy = GunnerUpgrades:WaitForChild('Gunman1'):Clone()
TowerDecoy.Parent = workspace.Maps.Tutorial
TowerDecoy:SetPrimaryPartCFrame(CFrame.new(Mouse.Hit.Position))
return TowerDecoy
end
--//Mouse Move\\--
Mouse.Move:Connect(function()
if IsSpawning == false or CurrentDecoy == nil then return end
local posX = Mouse.Hit.X
local posY = Mouse.Hit.Y + 0.8
local posZ = Mouse.Hit.Z
CurrentDecoy:SetPrimaryPartCFrame(CFrame.new(Vector3.new(posX, posY, posZ)))
CurrentDecoy:SetPrimaryPartCFrame(CFrame.new(Vector3.new(posX, posY, posZ))*CFrame.Angles(0,math.rad(90*Rotation),0))
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Blacklist
overlapParams.FilterDescendantsInstances = {workspace.Placeable, CurrentDecoy:GetChildren()}
local touchingParts = workspace:GetPartsInPart(CurrentDecoy.Outline, overlapParams)
for _, v in pairs(touchingParts) do
if v.Name == 'Outline' then
CanPlace = false
CurrentDecoy.Outline.Color = Color3.fromRGB(255,0,0)
return
end
end
if (Mouse.Target ~= workspace.Placeable) then
CanPlace = false
CurrentDecoy.Outline.Color = Color3.fromRGB(255,0,0)
elseif (Mouse.Target == workspace.Placeable) then
CanPlace = true
CurrentDecoy.Outline.Color = Color3.fromRGB(68,255,26)
end
end)
--//Player Clicks Mouse\\--
Mouse.Button1Down:Connect(function()
if IsSpawning == false or CurrentDecoy == nil or CanPlace == false then return end
CurrentDecoy.Parent = workspace
CurrentDecoy.Outline.Transparency = 1
CurrentDecoy = nil
SpawnButton.Visible = true
IsSpawning = false
end)
--//Button Press\\--
SpawnButton.MouseButton1Click:Connect(function()
if IsSpawning == false then
SpawnButton.Visible = false
IsSpawning = true
CurrentDecoy = CreateDecoy()
Mouse.TargetFilter = CurrentDecoy
end
end)
--//Input Functions\\--
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.R and not gameProcessedEvent then
if IsSpawning == false or CurrentDecoy == nil then return end
local modelCFrame = CurrentDecoy:GetPrimaryPartCFrame()
CurrentDecoy:SetPrimaryPartCFrame(modelCFrame * CFrame.Angles(0, math.rad(90), 0))
if Rotation == 1 then
Rotation = 2
elseif Rotation == 2 then
Rotation = 3
elseif Rotation == 3 then
Rotation = 4
elseif Rotation == 4 then
Rotation = 1
end
end
end)
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.X and not gameProcessedEvent then
if IsSpawning == false or CurrentDecoy == nil then return end
CurrentDecoy:Destroy()
CurrentDecoy = nil
IsSpawning = false
SpawnButton.Visible = true
end
end)
How should I go about sending the information I can safely to the server through remote events? I have tried this already but it didn’t work very well. Thank you for the help in advance!