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

i want to make my gems give speed instead of gems, how do i do that?

so i am making a new game again and i have gems as a currency but the map is very big so i want some gems to give players speed instead but i don't know how, so here is my regular gem script, how do i change it to be what i want?

currency = "Gems"	
amnt = 60		
debounce = false		

	function onTouch(hit)
		if hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == false then
			if game.Players:findFirstChild(hit.Parent.Name) ~= nil then
			ThisPlayer = game.Players:findFirstChild(hit.Parent.Name)
			ThisPlayer.leaderstats:findFirstChild(currency).Value = ThisPlayer.leaderstats:findFirstChild(currency).Value + amnt
			script.Parent.Transparency = 1
			script.Parent.CanCollide = false
			debounce = true
			wait(21)		--NOTE Respawn time
			script.Parent.Transparency = 0
			script.Parent.CanCollide = true
			debounce = false
			end
		end
	end


script.Parent.Touched:connect(onTouch)

4 comments

0

you probably will need to make another script that checks if, and how many gems of different types a players has.Otherwise you could have a player variable that your add to when a speed gem is picked up.

0

???

0

Just make it whenever you touch a gem the walkspeed of the player gets larger. Not that hard

0

i tried that idiot!why do you think im here!

1 answer

First off, there's a MUCH better way to get the player of a hit character.

game.Players:GetPlayerFromCharacter(character)

This will return the player of the character. In this case, hit.Parent would be the character.

game.Players:GetPlayerFromCharacter(hit.Parent)

Now, to give speed instead of currency. Of course, you would want to get rid of the script that adds currency to their player (I'm assuming that you made this script yourself and you can do this yourself). Then, you would need to get their humanoid.

local hum = hit.Parent:FindFirstChild("Humanoid")

This returns the Humanoid! Assuming you're smart enough to know how to edit this and get these values, and that you understand that "WalkSpeed" is a property of humanoid. Now, of course, you want to give it a duration. This is where you use spawn(). Using spawn(), you can run a code sample without halting the rest of the code. After they get the speedboost, you can do this:

spawn(function()
	hum.WalkSpeed = hum.WalkSpeed * 2
	wait(10)
	hum.WalkSpeed = hum.WalkSpeed / 2
end)

This spawn will run the rest of the code, and increase the player's walkspeed for 10 seconds.

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