Great! More coding, more stupid errors. I’m currently coding a magnet and well
- its vulnerable against exploiters
- the client side visual effects aren’t working.
(even though attachment exists and I EVEN USED WAITFORCHILD!)
Client:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local magnetEvent = script.Parent.MagnetEvent
local tool = plr.Backpack:FindFirstChildOfClass("Tool")
if tool:GetAttribute("magnet") then
tool.Equipped:Connect(function(mouse)
magnetEvent:FireServer(tool)
end)
end
magnetEvent.OnClientEvent:Connect(function(plr,coin)
local alignPos = Instance.new("AlignPosition",script.Parent.Handle.coinPart.Attachment)
local beam = workspace.FX.MagnetBeam:Clone()
local tickA = tick()
beam.Parent = tool
beam.Attachment0 = coin.Attachment
beam.Attachment1 = script.Parent.Handle.coinPart.Attachment
alignPos.MaxForce = 2000
alignPos.RigidityEnabled = false
alignPos.MaxVelocity = tool:GetAttribute("range") * 8
coin.Anchored = false
coin.Massless = true
end)
Server:
script.Parent.MagnetEvent.OnServerEvent:Connect(function(plr,tool)
local char = plr.Character
while task.wait(0.1) do
local o = OverlapParams.new()
o.CollisionGroup = "Coins"
local result = workspace:GetPartBoundsInBox(char.HumanoidRootPart.CFrame,Vector3.one * (tool:GetAttribute("range") * 2),o)
if result ~= {} then
for i,v in pairs(result) do
local coin = result[i]
plr:WaitForChild("leaderstats").Coins.Value = coin:GetAttribute("value")
script.Parent.MagnetEvent:FireClient(plr,coin)
end
end
end
end)
I’m pretty sure I’m overthinking this as I almost never use FireClient() but I don’t know what else to do.
Edit: you may want the hierarchy of the tool