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

Sell Tool/Weapon System failure, why? Fixable?

Hello all! I am in an urgent issue, and haven't been able to fix it! I've read some on the DevForum, and as well as on the developer wiki, but I cannot seem to understand how to do this, or what to do!

I've made various attempts, my latest will be posted below, but essentially what I am trying to accomplish is that when a player touches a brick, that the brick takes an item(if in their inventory), and gives them a specific amount of Gold for that item.

NOTE: This is a CUSTOM INVENTORY! It is located in the PlayerGui so, it's needed to call the playergui, as well, as find the weapon, and if the weapon is there, remove it, and give the Gold As well, this is in a ServerScript located INSIDE the part.

Here's my code, any and all help is appreciated! --

local player = game.Players.LocalPlayer
local char = player.Character
local wepon = player.char.PlayerGui.Arsenal.Backpack:WaitForChild("WoodenSword")
local gold = game.Players.LocalPlayer.leaderstats.Gold

script.Parent.Touched:Connect(function(touch)
	if touch then
		wepon:Destroy()
		gold.Value = gold.Value+100
	end
end)

5 comments

0

Kinda hard to sit down and walk you through every part of this but here is a useful piece ... look into using modules to store the values of all your weapons instead of writing out their value in your scripts.

0

no do not do this, if you follow what this guy says then that can be exploited since local scripts can edit the text inside a module script. this means that exploiters can change the value of those things

0

Wasn't planning on doing that I know they can be edited via exploit^

0

would not have suggested you use a local script to access a module. If I every do it, I send a request to the server which then accesses the module .

0

^How would I go around putting this in a script?

1 answer

script.Parent.Touched:Connect(function(touch)
	if touch.Parent:FindFirstChild("HumanoidRootPart") then--to see if its a player or not that touches it
		local player = game.Players:GetPlayerFromCharacter(touch.Parent)--self explainatory
		local gold = player.leaderstats.Gold
		local wepon = player.Character.PlayerGui.Arsenal.Backpack:FindFirstChild("WoodenSword")
		if wepon then--checks if the sword is there
			wepon:Destroy()
			gold.Value = gold.Value + 100
		end
   	 end
end)

make it a server script instead

1 comment

0

:GetPlayerFromCharacter Won't function, as the PlayerGui isn't in the PlayerModel, it's in the "Players" category under localplayer. So that code doesn't function.

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