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

Cloning a gui to a player under certain conditions?

Asked by 10 years ago

I have this localscript inside a sword, and there's a part that's not working. The output gives no error message at all. Please help. The specific part that has a problem is supposed to make a gui that is in the sword be cloned to the player that activated it.

local Tool = script.Parent;

enabled = true
function onButton1Down(mouse)
if not enabled then
return
end

enabled = false
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"

wait(.5)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
enabled = true

end

function onEquippedLocal(mouse)

if mouse == nil then
print("Mouse not found")
return 
end

--This part is the problem

player = game.Players.LocalPlayer
if script.Parent.Parent.Ability1name ~= "Swords" and script.Parent.Parent.Ability2name ~= "Swords" and script.Parent.Parent.Ability3name ~= "Swords" and player.PlayerGui:FindFirstChild("Train") == false then
script.Parent.Train:Clone().Parent = player.PlayerGui
end

mouse.Icon = "rbxasset://textures\\GunCursor.png"
mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end


Tool.Equipped:connect(onEquippedLocal)

2 answers

Log in to vote
0
Answered by
hiccup111 231 Moderation Voter
10 years ago

(line 28) 'Ability1name' - 'Ability3name'. You're reading an Instance.

If these are StringValues, do

Ability1name.Value ~= "Sword"

If in doubt, put a bunch of Prints in, see what's passing and what's not.

0
Thanks so much! pivot513 5 — 10y
0
Welcome hiccup111 231 — 10y
Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

The way that you've done it is not the most efficient way. Let me give it a try. I'd like to first apologize for lack of spacing due to my Studio updating.

player = game.Players.LocalPlayer -- This better be a local script..
if not script.Parent.Parent.Ability1name == "Swords" and not script.Parent.Parent.Ability2name == "Swords" and not scipr.Parent.Parent.Ability3name == "Swords" and not player.PlayerGui:FindFirstChild("Train") then
script.Parent.Train:clone().Parent = player.PlayerGui
end

Answer this question