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

Change the value inside of the object when the dialog selected?

Asked by 8 years ago

I want it to like when the player selects the dialogChoice the value named "Owner" inside of the object to change to the players name when selected. hope this isn't to not understandable?

script.Parent.DialogChoiceSelected:connect(function(player, choice)
if choice == script.Parent.Choice1 then
local boat = game.Lighting.yo:clone()
boat.Parent=player.Character
boat:makeJoints()
if boat.Parent.Owner.Value==nil then
boat.Parent.Owner.Value=player.Character.Name
return
end
end
end)
1
Hit edit, then put your code in the code block with the 'Lua JamesLWalker 297 — 8y
0
> "hope this isn't to not understandable?" - Doesn't stick it in a code block. User#6546 35 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

From your description it seems that the "Owner" value is inside the boat, but right now you're trying to find it in player's character due to the boat.Parent.Owner statement.

Also consider using line breaks and tabs. Yes, they aren't necessary and won't affect code functionality, but will make it a lot more readable for yourself and others.

script.Parent.DialogChoiceSelected:connect(function(player, choice) 
    if choice == script.Parent.Choice1 then 
        local boat = game.Lighting.yo:clone()  -- Please don't use lighting as storage anymore, move it to ReplicatedStorage or ServerStorage
        boat.Parent=player.Character -- Note that boat will turn invisible in first person and will get destroyed once player dies. Consider placing it in workspace instead and rely on the Owner value?
        boat:MakeJoints() 

        if  boat.Owner.Value == "" then -- The string value exists by default, so it's not nil. Rather check for empty string
            boat.Owner.Value = player.Name -- No need to use character's name, using player's name would be more reliable
            return 
        end 
    end 
end)
Ad

Answer this question