Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Sell Tool/Weapon System failure, why? Fixable?

Asked by
BryanFehr 133
5 years ago

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)
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. ForeverBrown 356 — 5y
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 Gameplayer365247v2 1055 — 5y
0
Wasn't planning on doing that I know they can be edited via exploit^ BryanFehr 133 — 5y
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 . ForeverBrown 356 — 5y
0
^How would I go around putting this in a script? BryanFehr 133 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago
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

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. BryanFehr 133 — 5y
Ad

Answer this question