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

How do I make this work in a script instead of locally?

Asked by 4 years ago

How do I go about making this last bit work in a script, it's supposed to make certain parts invisible whenever I equip my tool, and make them visible on unequip. Right now it doesnt do anything on equip or unequip.

local sp = Script.Parent

sp.Equipped:connect(function()
    local SheatheLocation = game.Players.LocalPlayer.Character:FindFirstChild("DaggerBelt")
    local SheatheParts = SheatheLocation:GetChildren()
    for i = 1, #SheatheParts do
        if SheatheParts[i].Name ~= "Middle" then
            if SheatheParts[i].Name ~= "Sheathe" then
            SheatheParts[i].Transparency = 1
            end
        end
    end
end)

sp.Unequipped:connect(function()
    local SheatheLocation = sp.Parent.Parent.Character:FindFirstChild("DaggerBelt")
    local SheatheParts = SheatheLocation:GetChildren()
    for i = 1, #SheatheParts do
        if SheatheParts[i].Name ~= "Middle" then
            if SheatheParts[i].Name ~= "Sheathe" then
            SheatheParts[i].Transparency = 0
            end
        end
    end
end)

Cheers!

0
good start would be "sp = script.Parent" and not "sp = Script.Parent" Wiscript 622 — 4y
0
yea NSMascot 113 — 4y

1 answer

Log in to vote
0
Answered by
NSMascot 113
4 years ago

1) make a remoteevent in replicatedstorage, call it equiptoolevent 2) make another remoteevent in replicatedstorage, call it unequiptoolevent 3) put this in your localscript

local equipevent = game.ReplicatedStorage.equiptoolevent
local unequipevent = game.ReplicatedStorage.unequiptoolevent

sp.Equipped:connect(function()
equipevent:FireSever()
end)

sp.Unequipped:connect(function()
unequipevent:FireServer()
end)

4) majke a serverscript in serverscriptservice, call it toolscript 5) put this into the script

local equipevent = game.ReplicatedStorage.equiptoolevent
local unequipevent = game.ReplicatedStorage.unequiptoolevent 

equipevent.OnServerEvent:Connect:function(player)
    --write equip script here
end)
unequipevent.OnServerEvent:Connect:function(player)
       ---write equip script here
end)

this script fixing another error, other players won't see when the player makes thier tool invisible/visible

Ad

Answer this question