Does my script work?

I am not quite sure if my script would work because I am soon to get premium but I have not got it yet and I am still a pretty new developer so help would be appreciated.

here’s my script:

local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local killall = game.Workspace.Tool
local killall:Clone = killall:Clone()

killallclone.Parent = workspace

if player.MembershipType == Enum.MembershipType.Premium then
killall.Parent = player
elseif Enum.MembershipType.None then
killallclone:Destroy()
end

would this script give the “killall” tool to a premium and delete the “killallclone” if there isn’t a premium?
that’s what I am trying to do.

here is a picture of the workspace.

sorry if this is in the wrong topic. but would this script work???

one last question would all the scripts inside my tool (even though I don’t have any yet) work?
(there is probably a much easier way to do it but I do not know how to do it yet)

Thanks, hellobeede.

Why don’t you just replace the if statement to see if it would work?

Small problem, change the killal.Parent to killalclone.Parent

what do you mean?
i dont really understand that.

Speaking of LocalScripts, I am not quite certain whether the tool will be successfully given to the player themselves, but the concern is mostly on what happens next if the tool is given to the player. This tool will not replicate to other players, and should probably work as accordingly somehow.

I don’t know about the detail of the original tool being in workspace. There will be an issue if someone magically picks this tool up, therefore causing an issue and breaking the code.

This line:
local killall:Clone = killall:Clone()

…will never work, because : is reserved character to an operator.

sorry I’m still really new to the developing world.

ok. should I scrap this code and try to make a new one?

You should proooobably do that, but I would advise otherwise and work on the same code but rewriting it a little around it.

Although that, it would be extremely helpful if you provided the purpose of this tool and the script itself. Context matters a lot in most cases of scripting support.

@anon81993163 or how could I make this code work.
all I want it to do is give a tool to a premium.

ok. I might go change the script a little come back later.

There are a lot of ways to do this, but I can try to figure out this in the best way possible:

  1. Store the tool in ReplicatedStorage, very important to manage your objects that exists for storaging.
  2. Use a server script and store this script in ServerScriptService, a canonical service for server scripts.
  3. Write the code, remember to use correct services like Players. Also each Player has a Backpack which should contain these tools.
local Players = game:GetService("Players")

local PremiumTool = ReplicatedStorage.Tool

Players.PlayerAdded:Connect(function(player)
	if player.MembershipType == Enum.MembershipType.Premium then
		PremiumTool:Clone().Parent = player.Backpack -- a backpack is used to hold tools, not player object
	end
end)

Beware that this code doesn’t give you the tool again after you died.

would this be all I needed to do?

Probably, but there’s some things I left behind for you to explore and tackle. It wouldn’t be a learning experience if that wasn’t the case.

1 Like

ok thanks!!! C: sooooo much!!!