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

How make a script that you clicked a Image Button in a gui and then it gives you a weapon?

Please help me>>

Noobish scripter here

1 answer

✓ Accepted answer

This is simple. First, you start with the click function;

script.Parent.MouseButton1Click:connect(function()

end)

then you should check if the player already has the item.

if not game.Players.LocalPlayer.Backpack:FindFirstChild("Sword") then

end

and then give the player the item.

print("Giving "..game.Players.LocalPlayer.Name.." a sword.")
Sword = game.ReplicatedStorage.Sword:Clone() --Clone the sword, change this to wherever your sword is.
Sword.Parent = game.Players.LocalPlayer.Backpack --Parenting the newly cloned item

and if they already have it

elseif game.Players.LocalPlayer:FindFirstChild("Sword") then
print(game.Players.LocalPlayer.Name.." Already received the sword.")

so it should look like this in the end;

--Put this in the image button
--This must be a local script.
script.Parent.MouseButton1Click:connect(function() --Clicked
if not game.Players.LocalPlayer.Backpack:FindFirstChild("Sword") then	--If they dont already have the sword
print("Giving "..game.Players.LocalPlayer.Name.." a sword.")
Sword = game.ReplicatedStorage.Sword:Clone() --Clone the sword, change this to wherever your sword is.
Sword.Parent = game.Players.LocalPlayer.Backpack --Parenting the newly cloned item
elseif game.Players.LocalPlayer:FindFirstChild("Sword") then
print(game.Players.LocalPlayer.Name.." Already received the sword.")
end
end)

3 comments

0

Thanks but on Line06 what do i put in () Please give me an example!

0

You don't put anything in '()'

0

you can remove the "print" if you want, it affects nothing to the script its only give you some message/warnings in the output

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