I have a game with multiple swords with a script in each of them. But if I wanted to change the script, then I have to annoyingly copy + paste it into the other tools. Is there a way to make it easier, such as a global script or a script injector?
1 Like
Like sam said, using CollectionService is a good way of approaching what you want.
This is a code example on how you can do it.
-- Handle when a sword is equipped.
Character.ChildAdded:Connect(function(Child)
if Child:IsA('Tool') and CollectionService:HasTag(Child, 'Sword') then
-- Equip logic
Child.Activated:Connect(function()
-- Tool activated logic
end)
end
end)
-- Handle when a sword is unequipped.
Character.ChildRemoved:Connect(function(Child)
if Child:IsA('Tool') and CollectionService:HasTag(Child, 'Sword') then
-- Unequip logic
end
end)
1 Like
Should I use a local script or a server script for this?
CollectionService works… But my question is: why?
Not to downplay the other responses here, but you should realistically speaking be using ModuleScripts, that’s quite literally the entire purpose of them: returning code that’s shared by multiple assets. (In your case tools.)
I agree with node, modulescript is more suitable.
How would I do it this way, then?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.