generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Give Player/ Starterpack

Previous Thread :: Next Thread 
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
23 Jun 2015 07:03 PM
Hello everyone, I have been working on making a shop, and I have a button(brick) and this is the script that is inserted, I'm trying to make it so it will give the player "cerulean"( a weapon I put in workspace) after he has stepped on the brick, here is the script, I just cant seem to figure out how to make it work.

enabled = false
script.Parent.Touched:connect(function(hit)
humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil and enabled == true then
enabled = false
player = game.Players:GetPlayerFromCharacter(hit.Parent)
points = player.leaderstats.Points
if player.leaderstats.Points.Value > 15 then
points.Value = points.Value -5
gun = game.ServerStorage.cerulean:Clone()
if player.Backpack:FindFirstChild(gun.Name) ~= nil then return end
gun.Parent = player.Backpack
wait(5)
enabled = true

end
end
end)
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
23 Jun 2015 07:08 PM
A weapon in ServerStorage*
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
23 Jun 2015 07:16 PM
You start out with enabled being false and then you ask if it is true to do the rest of the script.
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
23 Jun 2015 07:17 PM
You should also check if the gun is in the backpack first, then subtract the points. Otherwise, even if you have the gun, it would subtract the points.
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
23 Jun 2015 07:21 PM
Im sorry, but I dont understand the post you had just sent.

to check for the gun, first you would do
if player.Backpack.cerulean = true then end
else
(Rest of script here)

I dont exactly know how to put the cerulean in from :clone() -ing it.
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
23 Jun 2015 07:25 PM
bump
Report Abuse
ImageLabel is not online. ImageLabel
Joined: 08 Dec 2012
Total Posts: 428
23 Jun 2015 07:28 PM
You can save yourself a few lines by directly searching for a player matching
a certain character, usually (hit.Parent), instead of looking for a Humanoid before
the player.

local toggle = false

script.Parent.Touched:connect(function (hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
toggle = not toggle

-- if player exists and toggle == true
if player and toggle then
-- define points
points = player.leaderstats:FindFirstChild('Points')

-- if points exists and its value is greater than 15
if points and points.Value > 15 then
-- subtract 5
points.Value = points.Value - 5
-- define gun, backpack, starterGear..
local gun = game.ServerStorage:FindFirstChild('cerulan')
local backpack = player.Backpack
local starterGear = player.StarterGear

-- if gun exists and isn't already in the player's backpack
if gun and not backpack:FindFirstChild(gun.Name) then
-- clone them to the backpack, and the starterGear
gun:clone().Parent = backpack
gun:clone().Parent = starterGear
end
end
wait(5)
toggle = not toggle
end
end)
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
23 Jun 2015 07:36 PM
Hi imagelabel, thank you for the response and taking your time to script(it works by the way!)

I understand almost everything in the script, except for a few things, would you mind explaining them for me? I would really appreciate it.

toggle = not toggle
--Im not really sure what this means exactly? Arent you contradicting yourself?

if player and toggle then
-- I can somewhat understand what this means, it is checking if both are true, couldnt you do

if player and toggle == true then

-- Would this be the same outcome?
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
23 Jun 2015 07:40 PM
b2
Report Abuse
ImageLabel is not online. ImageLabel
Joined: 08 Dec 2012
Total Posts: 428
23 Jun 2015 07:42 PM
The logical operator `not` in front of a boolean value would set it equal to it's opposite. If `toggle` was true, not true would be false... and vice-versa.

`if toggle == true` would indeed be similar to `if toggle`, because as long as the condition is true, which it should be because of the toggle earlier on in the snippet, both work.
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
23 Jun 2015 07:50 PM
Whenever you already have the Gun/weapon, it will still deduct 5 points from the player
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
23 Jun 2015 07:55 PM
So I tried to make one similar to yours, just on my own, and it doesnt seem to work >.<
I have no idea whats wrong with it.

enabled = false
script.Parent.Touched:connect(function(hit)
humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil and enabled == true then
enabled = false
player = game.Players:GetPlayerFromCharacter(hit.Parent)
points = player.leaderstats:FindFirstChild("Points")
if points.Value > 15 then
points.Value = points.Value -5

local gun = game.ServerStorage:FindFirstChild("crulean")
local backpack = player.Backpack
local startergear = player.StarterGear

if gun and not backpack:FindFirstChild(gun.Name) then
gun:clone().Parent = backpack
gun:clone().Parent = startergear
end
end
wait(5)
enabled = true
end
end)
Report Abuse
ImageLabel is not online. ImageLabel
Joined: 08 Dec 2012
Total Posts: 428
23 Jun 2015 08:04 PM
As cgjnm already pointed out to you, you are setting the value of the boolean to false on the first line, and checking if its true on the 4th. Unless you change it beforehand, it will never pass condition check.

I also already said there's no need to check for the humanoid.. Everything is in the snippet i gave you.. so yeah. Read it over and cross-check with yours.

Au revoir!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image