Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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!

2 comments

0

good start would be "sp = script.Parent" and not "sp = Script.Parent"

0

yea

1 answer

  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)
  1. majke a serverscript in serverscriptservice, call it toolscript
  2. 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

This discussion is preserved as it was. New answers, comments, and votes are closed.