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

?Probably problem in "if" but where a realy dont know..

Asked by 4 years ago

This script is inside the player's "Rebirth Gui", but it doesn't work .. The problem is probably inside the condition, but where ?! Please help..

script.Parent.MouseButton1Click:Connect(function() --on Player Click Buy..
    local player = script.Parent.Parent.Parent.Parent.Parent --player
    --//Variables//--
    local gui = player.PlayerGui--gui
    local Rgui = gui.RebirthGui--Rgui
    local data = player.Data --data
    local money = data.Money.Value --money
    local rcoins = data.rcoins.Value  --rcoins
    local me =script.Parent
    local roud = me.TextButton_Roundify_12px
    local prize = script.Parent.Parent.Parent.prize.Value
    local frame = me.Parent
    local notEnoughCoins = frame.notEnoughCins
    local transfer = frame.transfer
    local hrac = game.Workspace[player.Name]
    local head = hrac:WaitForChild("Head")
    local howMuch = script.Parent.Parent.Parent.howMuch.Value
    --local buySound = head:WaitForChild("buySound")  --Add sounds soon....

                                    --/SCRIPT/--
    if money > prize then
        money = (money - prize)
        rcoins = rcoins + (howMuch * 1800)
    end


end) --End
0
You should've put more details like what you want it to do and in which line it errored etc. Trading_Opportunity 191 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

A couple of things you need to correct:

  1. When a property is accessed and assigned to a variable, the current value of the property is recorded, not a reference.
local property = Instance.Name
property = “NewName”
print(Instance.Name == “NewName”) --> false, the actual property doesn’t change
Instance.Name = “NewName”
print(Instance.Name == “NewName”) --> true, it has changed now
  1. Changes made by clients do not replicate to the server. You must use remotes to initiate changes from client to server.

  2. The local player can be referred to simply as game.Players.LocalPlayer, the extensive usage of .Parent is unnecessary and cluttering.

See also: Handling properties: https://developer.roblox.com/en-us/videos/Intro-to-Scripting-Changing-Properties Learning about replication: https://developer.roblox.com/en-us/api-reference/property/Workspace/FilteringEnabled

Ad

Answer this question