Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Would I Change GetFullName to a directory?

Asked by 5 years ago

ok, so I have filtering enabled and Im trying to make a destroy part script with a pickaxe. Heres the localScript,

local swing = script.Parent.Swing
local db = 5
oof = false
event = game:GetService("ReplicatedStorage").BlockBreak
script.Parent.Activated:Connect(function()
    if not oof then
        oof = true
        local plr = game.Players.LocalPlayer
        local Char = workspace:WaitForChild(plr.Name)
        print(Char)
        if Char ~= nil then
            local animTrack = Char.Humanoid:LoadAnimation(swing)
            animTrack:Play()
            db = 6
            wait(0.8)
            db = 5
        end
        wait(5)
        oof = false 
    end

end)
script.Parent.Handle.Touched:Connect(function(hit)
    if db == 6 then
        local naa = hit.Parent:FindFirstChild("HitTag")
        if naa ~= nil then
            event:FireServer(naa:GetFullName(),hit.Parent:GetFullName())
        end
    end
end)

And ServerScript:

event =  game:GetService("ReplicatedStorage").BlockBreak
event.OnServerEvent:Connect(function(plr,bVal,name)
    loc = name
    loc2 = bVal

    print("Recieved Order from "..plr.Name.." to break ".. loc)
    if loc ~=nil then
        wait(1)

        name.Parent = nil
        print("Logged")
        loc.Parent:Destroy()
    end
end)

The problem is that name is a string, how would I turn it into a directory so I can destroy the part?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You should do this on the server so that the client does not fire the remotes you have through exploits. I wrote a simple script that does this. Please put it in ServerScriptService.

local Players = game:GetService("Players");
local Tool = script.Tool -- Tool location
local PlayerTools = {};


function giveTool (Player)
    Player:WaitForChild("Backpack");
    local newTool = Tool:Clone();
    newTool.Parent = Player.Backpack;

    local playerTool = PlayerTools[Player.UserId]
    if playerTool then
        if playerTool.touchConnection then playerTool.touchConnection:disconnect(); end
        if playerTool.activatedConnection then playerTool.activatedConnection:disconnect(); end
        if playerTool.tool then playerTool.tool:Destroy() end
    end

    local isActivated = false;

    local touchConnection = newTool.Handle.Touched:Connect(function(hit)
        if not isActivated then return end
        if hit and hit:FindFirstChild("HitTag") then
            hit:Destroy()
        end
    end)

    local activatedConnection = newTool.Activated:Connect(function()
        if isActivated then return end
        isActivated = true
        wait(0.8)   
        isActivated = false
    end)
    PlayerTools[Player.UserId] = {
        tool=newTool,
        touchConnection= touchConnection,
        activatedConnection = activatedConnection
    }   

end

Players.PlayerAdded:Connect(function(Player) 
    giveTool(Player);

    Player.CharacterAdded:Connect(function(character)
        giveTool(Player)
    end)
end)
Ad

Answer this question