#Would this code have any issues in multiplayer?

1 messages · Page 1 of 1 (latest)

covert spruce
#
local RepStorage = game:GetService("ReplicatedStorage")
local CableEvent = RepStorage:WaitForChild("Cable")
local BuildEvent = RepStorage:WaitForChild("Build")
local CableTool = RepStorage:WaitForChild("CableTool")
local BuildTool = RepStorage:WaitForChild("BuildTool")
local ToolEquiped = false

--Tool equiping function
local function EquipAndDequip(tool, plr, ToolOn)
    local character = plr.Character
    if ToolOn == true then
        local CableTool = character:FindFirstChild(tool.Name)
        CableTool:Destroy()
        ToolOn = false
    else
        local CableTool = tool:Clone()
        CableTool.Parent = character
        ToolOn = true
    end
    return ToolOn
end


CableEvent.OnServerEvent:Connect(function(plr)
    --Tool equiping
    ToolEquiped = EquipAndDequip(CableTool, plr, ToolEquiped)
end)

BuildEvent.OnServerEvent:Connect(function(plr)
    --Tool equiping
    ToolEquiped = EquipAndDequip(BuildTool, plr, ToolEquiped)
end)

That is the code, and sorry if its bad i dont have a lot of experience (im happy that i even made this), and i would like to know if this would work on multiplayer, its on a script in serverScriptService

frail mortar
#

why are you storing ToolOn in a variable whats the point of that

covert spruce
frail mortar
#

like in the events ToolEquiped = … thats what i mean

#

oh i get ut

#

it

#

yeah this wont work for multiplayer

covert spruce
frail mortar
#

Yeah ToolEquiped is the same for everyone

covert spruce
frail mortar
#

idk if im missing something cause im on my phone rn but you are not rlly using ToolEquiped

#

oh ye

#

u are

covert spruce
#

I think im going to handle all the logic in a local script and only equip the tool in the server script, would that work?

frail mortar
#

what exactly does CableTool or what is it for

covert spruce
#

for now

frail mortar
#

well if its in replicatedstorage ts doesnt even make sense cause exploiters have access to that

covert spruce
vapid blazeBOT
#

studio** You are now Level 3! **studio

frail mortar
#

is everyone allowed to use it

covert spruce
frail mortar
#

then just make it client sided

covert spruce
#

like its the essential tool for the game

frail mortar
#

yeah just make it client sided

covert spruce
#

i need a server script too

frail mortar
#

make a parameter for equiped and unequiped in your remote event and just toggle it like that you don’t need to rlly always know whats the current state

#

yk what i mean

covert spruce
#

like a atribute boolean for equiped and unequiped?

frail mortar
#

no

covert spruce
#

OHHH

#

i get it

#

like event:FireServer(toolOn)?

frail mortar
#
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cableEvent = ReplicatedStorage:WaitForChild("Cable")
local buildEvent = ReplicatedStorage:WaitForChild("Build")
local cableTool = ReplicatedStorage:WaitForChild("CableTool")
local buildTool = ReplicatedStorage:WaitForChild("BuildTool")


local function toggleTool(tool, plr, toolActive)
    local character = plr.Character

    if toolActive == true then
        local tool = character:FindFirstChild(tool.Name)
        tool:Destroy()
        return
    end

    tool:Clone().Parent = character
end

cableEvent.OnServerEvent:Connect(function(plr, toolActive)
    toggleTool(cableTool, plr, toolActive)
end)

buildEvent.OnServerEvent:Connect(function(plr, toolActive)
    toggleTool(buildTool, plr, toolActive)
end)
#

check this

#

wait

#

actually

#
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local cableEvent = ReplicatedStorage:WaitForChild("Cable")
local buildEvent = ReplicatedStorage:WaitForChild("Build")
local cableTool = ReplicatedStorage:WaitForChild("CableTool")
local buildTool = ReplicatedStorage:WaitForChild("BuildTool")


local function toggleTool(tool, plr, toolActive)
    local character = plr.Character

    if toolActive == true then
        character:FindFirstChild(tool.Name):Destroy()
        return
    end

    tool:Clone().Parent = character
end

cableEvent.OnServerEvent:Connect(function(plr, toolActive)
    toggleTool(cableTool, plr, toolActive)
end)

buildEvent.OnServerEvent:Connect(function(plr, toolActive)
    toggleTool(buildTool, plr, toolActive)
end)
#

this

covert spruce
#

yeah im doing that rn

frail mortar
#

yk what i mean tho

#

idk why the hell you would do this server sided but i guess

covert spruce
frail mortar
#

ye i know

#

but if a player holds a tool it should automaticly show it for the other users