Owner only tool script?

Hi there, I’ve tried the usual suspects for this - however, no matter what I’ve tried, it just seems to break the actual code of the tool when giving it to me.

I realise this seems like a problem with the framework of the tool and not the script, however, I can’t change the tool’s scripts as that’s not an option.

Current script:


local players = {"Player1"}
local gear = game.ReplicatedStorage.Weapons["Tool name"]

game.Players.PlayerAdded:connect(function(plr)
	plr.CharacterAdded:connect(function(chr)
		for i = 1, #players do
			if players[i] == plr.Name then 
				gear:Clone().Parent = plr:WaitForChild("Backpack")
			end
		end
	end)
end)

The tool gets stored in replicated storage but when the game retrieves it, the “ability” of the tool only client sided and the effects and animations don’t play for the other player - I tested it on a local server.

Therefore, my question is how can I create a script that keeps the tool within “StarterPack” but doesn’t appear to over players and only the owner (me).

Any suggestions would be appreciated! <3

3 Likes

wait so is this script in a server script(script) or a local script?
Depending this could work without putting it in the starterpack

3 Likes

Do something like this:

local owner = "your user id"

local players = game.Players
players.PlayerAdded:Connect(function(player)
      if player.UserId = owner then
            local tool = game.StarterPack["tool"]:Clone()

          tool.Parent = player.Backpack
      end
end)

I suggest to place the tool into serverstorage.

1 Like

The only problem is that it is quite vulnerable to exploiters. Just place the tool into server storage

1 Like

Cheers, but why is it vulnerable to exploiters? (Sorry if I’m asking the obvious).

1 Like

It means that people who well as many call it “hack” can just get the tool even if they shouldnt, thats why this wouldnt be the most recommended method unless you want cheaters to get this tool too.

1 Like

The problem seems to be that the tool in of itself is only appearing client-sided and not displaying for the player it’s attacking - it should be noted that the tool is an ability and not a physical handle either.

I know I’m not giving much to work with here but are there any common reasons a tool being stored in serverstorage would break?

1 Like

Hmm maybe. can I see your workspace to see how everything is? I think it might help me some

1 Like

Sorry my workspace is very cluttered and is going to be difficult to fit in a few screenshots but the layout is roughly like this:

Tool/ability tool is in “StarterPack” - with a script child.

Tool giver script in “ServerScriptService”.

Tool ability VFX in “ReplicatedStorage”.

1 Like

Ok well probably put the tool inside of ServerStorage in a folder or something.
And sense the question wasnt answered, this is a server script right? also are you using a local script to handle the entire tool? Like damage, cooldowns(If you have them), etc?

1 Like

No I’m using a normal script not a local script for the main mechanics.

1 Like

This is what you need to do to give a tool to only yourself when you join the game, and keep that tool even if you die or reset (server Script in ServerScriptService):

local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")

local OWNER_USER_ID = 173412116

local tool = ServerStorage.Weapons["Tool name"]

local function onPlayerAdded(player)
	if player.UserId == OWNER_USER_ID then
		tool:Clone().Parent = player.StarterGear
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

For this to work correctly you’ll need to place the Tool inside of a Folder named “Weapons” which is inside of ServerStorage

2 Likes

Cheers, I appreciate it but it seems my scripts won’t work around anything outside StarterPack - I’m guessing this is just the framework/design of my scripts so I’m just going to refine.

But it’s odd, the attack works on both screens when I put the tool inside of StarterPack but when I put it inside serverstorage it just shows client-sided view and doesn’t work on the player it’s attacking.

2 Likes

I do think you’ll need to reconsider your current framework if it’s causing you this kind of problem, it shouldn’t make a difference where a Tool is stored in the way it replicates unless some of the code inside of your Tool is able to run when the Tool is unequipped

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.